[PYTHON] When using ancestor query with Google Apps Engine, parent does not have to use real entity

I said what I wanted to say in the title. Strongly consistent is applied by using ancestor query.

from google.appengine.ext import ndb

class Customer(ndb.Model):
    name = ndb.StringProperty()

class Purchase(ndb.Model):
   price = ndb.IntegerProperty()

customer_entity = Customer(name='me', id='[email protected]')
purchase1 = Purchase(parent=customer_entity.key, price=100)
purchase2 = Purchase(parent=customer_entity.key, price=200)
purchase1.put()
purchase2.put()
print Purchase.query(ancestor=customer_entity.key).fetch()
#[Purchase(key=Key('Customer', '[email protected]', 'Purchase', 5414888608366592), price=200), Purchase(key=Key('Customer', '[email protected]', 'Purchase', 5977838561787904), price=100)]

key = ndb.Key('user', '[email protected]')
purchase3 = Purchase(parent=key, price=100)
purchase4 = Purchase(parent=key, price=200)
purchase3.put()
purchase4.put()
print Purchase.query(ancestor=key).fetch()
#[Purchase(key=Key('user', '[email protected]', 'Purchase', 4711201166589952), price=200), Purchase(key=Key('user', '[email protected]', 'Purchase', 6540788515209216), price=100)]

Recommended Posts

When using ancestor query with Google Apps Engine, parent does not have to use real entity
How to not load images when using PhantomJS with Selenium
How to write to update Datastore to async with Google Apps Engine
When you want to use it as it is when using it with lambda memo
How to deal with OAuth2 error when using Google APIs from Python