Reputation: 179
I wanted to ask if there is a direct and efficient way to get the child of a parent entity.
I am modelling a follower/ following relationship(like twitter). So I have a user model and a message model. I have a Follower and Following model which have a user model as a parent.
So whenever a user writes a message(or say tweet), all his followers should be able to get that. In this case I need to figure out who are the followers of the user(who sends a message).
Any help is greatly appreciated
Upvotes: 5
Views: 5447
Reputation: 1063
Another method of finding the children of an entity is to instantiate a ndb.Query
object, passing ancestor
to its constructor:
joe = Followed.get_by_id('joe')
query = ndb.Query(ancestor = joe.key)
followers = query.fetch()
This also provides a more general way to find the children of an entity without requiring their Kind
to be known in advance.
Upvotes: 0
Reputation: 16890
Use ancestor queries. https://developers.google.com/appengine/docs/python/datastore/queryclass#Query_ancestor Or https://developers.google.com/appengine/docs/python/ndb/queries#ancestor
Upvotes: 4