Google App Engine request (not filter) for child elements of an object

Are facility children available on request?

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() 

Suppose that 500 factories produced 500 products for a total of 250,000 products. Is there a way to generate a resource-efficient query that will return only 500 products made by one particular factory? The ancestor method is a filter, therefore, using, for example, Product.all (). Ancestor (factory_1) will require repeated calls to the data warehouse.

+6
google-app-engine ancestor gql
source share
1 answer

Although the ancestor is described as a β€œfilter,” it actually just updates the query to add an ancestor condition. You do not send a request to the data warehouse until you click on a request, so that it will work fine for you.

One minor point: 500 objects with the same parent can damage scalability because records are serialized for members of an entity group. If you just want to track the factory that made the product, use ReferenceProperty:

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

Then you can get all the products using:

 myFactory.products 
+8
source share

All Articles