Joydeep sinha
Joydeep sinha

Reputation: 179

Efficient way to get child entity/keys given a parent

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

Answers (2)

Tom Russell
Tom Russell

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

Related Questions