I'm attempting to model a recursive structure with App Engine NDB:
class Root(ndb.Model):
pass
class Node(ndb.Model):
#Node can have either a Root, or another Node as parent
pass
root_key = Key(Root, 1)
node_a = Key(Root, 1, Node, 2)
node_b = Key(Root, 1, Node, 3)
node_a_a = Key(Root, 1, Node, 2, Node, 4)
From here, I want to query the Root entity for immediate children. What I can do is to query for all descendants of the root:
Node.query(ancestor=root_key) # returns node_a, node_b, and node_a_a
What I'd like to do is:
Node.query(parent=root_key) # returns node_a, node_b
but it seems that querying by (immediate) parent key isn't supported by the ndb api. Hopefully I'm wrong. Looking forward to elucidation. Thanks