考虑以下代码片段:
from google.appengine.ext import ndb
import pprint
class Entity(ndb.Model):
name = ndb.StringProperty()
age = ndb.IntegerProperty()
entity = Entity()
entity.name = "hello"
entity.age = 23
entity.key = ndb.Key(Entity, "p1")
entity.put()
e2 = Entity()
e2.key = ndb.Key(Entity, "p2", parent=ndb.Key(Entity, "p1"))
e2.name = "he11o2"
e2.age = 34
e2.put()
我想查询没有的Entity表记录 与之关联的 parent 。对于上面的示例,它应该只生成 p1 实体。
我怎样才能做到这一点?
请您参考如下方法:
你不能。您只能查询索引中存在的内容。除非明确设置为 None(你不能为 parent 这样做),否则没有值(value)的东西不能被查询。
我可以建议的唯一方法是有一个计算属性或一些其他属性,如果没有父项或父键或标志,则将其设置为 None 。然后您可以查询所有 parent=None 的实体。 parent 是实体的属性。
