NDB是否仍使用default = None或属性设置为None进行索引? [英] Does NDB still index with default=None or properties set to None?

查看:89
本文介绍了NDB是否仍使用default = None或属性设置为None进行索引?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够运行如下查询:MyModel.query(MyModel.some_property == None)并获得结果.我知道如果不将default=<some default>放在属性中,将无法查询它,但是如果设置了default=None,它将为它编制索引吗?

I'd like to be able to run a query like: MyModel.query(MyModel.some_property == None) and get results. I know that if I don't put a default=<some default> in a property, I won't be able to query for it, but if I set default=None will it index it?

类似地,将值设置为None是否会使属性在ndb.Model中建立索引?如果将some_keyword_arg=None传递给构造函数怎么办?

Similarly, does setting values to None cause properties to be indexed in ndb.Model? What if you pass some_keyword_arg=None to the constructor?

我知道做类似ndb.StringProperty(default='')的事情意味着您可以查询它,只是不清楚使用None的语义.

I know that doing something like: ndb.StringProperty(default='') means you can query on it, just not clear on the semantics of using None.

推荐答案

将属性显式设置为None定义一个值,是的,默认情况下有效,该属性将被索引.假设None是特定属性类型的有效值.

Explicitly setting a property to None is defining a value, and yes defaults work and the property will be indexed. This assumes None is a valid value for a particular property type.

正如您指出的那样,会出现一些问题,通常您将None用作标准值,那么如何区分未提供的值和显式的None?

Some issues will arise, as you pointed out, often you use None as a sentinal value, so how do you tell between no Value provided and an explicit None?

这篇关于NDB是否仍使用default = None或属性设置为None进行索引?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆