Drathier
Drathier

Reputation: 14549

ndb.Query: only return items that is grandchild of other item

I have a structure with house in district in city and I need to search for houses in a specified city and/or district using ndb.Query (since I also need to filter for other properties).

City has a list of district's and district has a list of house's.

Note: there are no ancestors here, since this is part of a bigger graph, so ancestor queries are not possible.

Example:
Get all house's that have area > 500 in a specified city (by a field name in city).

Upvotes: 0

Views: 52

Answers (1)

Jaime Gomez
Jaime Gomez

Reputation: 7067

Since you cannot do JOINs, you would have to change your design a little bit.

The easiest option is to add city_name as a property for House, that seems to answer your example and general question.

If you can't change the model, or your queries are more complex, you could have another entity holding all the information you need for queries (your denormalization table), and use it only for that. House can be its ancestor and so you can do key only queries, which will save you time/money. Also try to define indexes for your most common queries.

Upvotes: 1

Related Questions