Google App Engine查询(不过滤)实体的子项 [英] Google App Engine Query (not filter) for children of an entity

查看:194
本文介绍了Google App Engine查询(不过滤)实体的子项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



鉴于:

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

class Product(db。模型):
子类,使用Product(parent = factory)来创建
@property
def factory(self):
return self.parent )
serial = db.IntegerProperty()

假设有500家工厂生产了500种产品共有250,000种产品。有没有办法形成一个资源高效的查询,将返回一个特定工厂制造的500个产品?祖先方法是一种过滤器,所以使用例如Product.all()。祖先(factory_1)需要重复调​​用数据存储。

解决方案

尽管祖先被描述为过滤器,它实际上只是更新查询以添加祖先条件。在你迭代查询之前,你不会发送请求到数据存储区,所以你有什么可以正常工作。

尽管有一个小问题:500个实体相同父母可能会伤害可伸缩性,因为写入被序列化为实体组的成员。如果您只是想跟踪生成产品的工厂,请使用ReferenceProperty:

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

然后您可以获取所有产品使用:

  myFactory.products 


Are the children of an entity available in a Query?

Given:

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

class Product(db.Model):
    """ Child kind, use Product(parent=factory) to make """
    @property
    def factory(self):
        return self.parent()
    serial = db.IntegerProperty()

Assume 500 factories have made 500 products for a total of 250,000 products. Is there a way to form a resource-efficient query that will return just the 500 products made by one particular factory? The ancestor method is a filter, so using e.g. Product.all().ancestor(factory_1) would require repeated calls to the datastore.

解决方案

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

这篇关于Google App Engine查询(不过滤)实体的子项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆