Is it possible to create references in Google App Engine?
Let's say I have a datastore that contains mother, father, and child objects. Insid开发者_运维问答e the Mother and Father objects I have a field called child which stores a reference to their child. Is it possible to reference this child from both mother and father without creating duplicate child instances for each (in the style of OOP). Is this how databases work at all?
Yes, you can use the db.ReferenceProperty to do exactly that.
A reference property simply stores the unique key of the entity it references. So the mother and father entities could each contain a copy of the key corresponding to their child like this:
class Child(db.Model):
... # child properties
class Father(db.Model):
child = db.ReferenceProperty(Child)
...
class Mother(db.Model):
child = db.ReferenceProperty(Child)
...
精彩评论