Reputation: 499
Consider the following code snippet:
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()
I want to query the Entity table records that doesn't have any parent associated with it. For the above example it should yield me only p1 entity.
How can I achieve this ?
Upvotes: 2
Views: 366
Reputation: 12986
You can't. You can only query for things that exist in an index. Things with no value unless explicity set to None (and you can't do that for parents) can't be queried.
The only way I can suggest is have a computed property or some other property that you set to None if no parent or the parent key or a flag. Then you can query for all entities with parent=None. parent
being a property of the entity.
Upvotes: 2