Google App Engine Query (not filter) for children of an entity

后端 未结 1 1738
情歌与酒
情歌与酒 2021-02-06 11:01

Are the children of an entity available in a Query?

Given:

class Factory(db.Model):
    \"\"\" Parent-kind \"\"\"
    name = db.StringProperty()

class P         


        
1条回答
  •  生来不讨喜
    2021-02-06 11:33

    Although ancestor is described as a "filter", it actually just updates the query to add the ancestor condition. You don't send a request to the datastore until you iterate over the query, so what you have will work fine.

    One minor point though: 500 entities with the same parent can hurt scalability, since writes are serialized to members of an entity group. If you just want to track the factory that made a product, use a ReferenceProperty:

    class Product(db.Model):
       factory = db.ReferenceProperty(Factory, collection_name="products")
    

    You can then get all the products by using:

    myFactory.products
    

    0 讨论(0)
提交回复
热议问题