开发者

How to query for models with specific parent (not any ancestor) in GAE

开发者 https://www.devze.com 2023-03-26 03:19 出处:网络
The docs says that ancestor will apply a filter of given ancestor being somewhere in the ancestry tree.

The docs says that ancestor will apply a filter of given ancestor being somewhere in the ancestry tree.

You can fil开发者_开发知识库ter your datastore queries to a specified ancestor, so that results contain only entities containing that ancestor. In other words, all of the results will have the ancestor as their parent, or parent's parent, or etc. Passing None as a parameter does not query for entities without ancestors and will return errors.

Can I somehow filter on one level, immediate ancestor relationship so that a query will provide models having specific parent? Or must I store parent relationship in a ReferenceProperty and filter on that?


You are right: querying for ancestor will get all parents, not only the direct one. To get the direct parent only, you must store it in a property (can be a ReferenceProperty or you can just store an encoded key in a StringProperty), then query for it.

0

精彩评论

暂无评论...
验证码 换一张
取 消