1

I have a data structure like this:

Restaurant > Menu > Category > Dish

when I load every dish for a restaurant, using:

q = db.Query(Dish)
q.ancestor('Restaurant Key')

I would like for every dish to come with a path with the property 'name' of each ancestor:

dish.path = "Cheesecake Factory > Meals > Beefs > Beef with Potatoes"

I know about dish.to_path(), but that only returns the ancestor's entity kind.

4

1 回答 1

2

This is possible if you are using they name of the object as the key, id ("Cheescake Factory", "Meals", "Beefs" etc.)

dish.key().to_path() should provide you with a list with the format [etc. grandparent-kind, grandparent-name/id, parent-kind, parent-name/id, kind, name/id>]

However, if the name of your object is not the key, you'll have to fetch each ancestor object to get the name. In this case, it would probably be better to store the entire path as a string inside your dish entity, so as to save on datastore fetches.

于 2012-12-05T15:45:11.780 回答