Hi Oliver,
Great suggestion and I want to make sure I understand the proposal. It
sounds like you would like the House model to have a parents back
reference and also a children back reference? How would the children
collection be given a collection name?
Here's some sample code to make this easier to follow:
from google.appengine.ext import db
from google.appengine.ext.db import polymodel
class House(db.Model):
address = db.IntegerProperty()
class Parent(polymodel.PolyModel):
house = db.ReferenceProperty(House, collection_name='parents')
class Child(Parent):
pass
h1 = House(address=5).put()
Parent(house=h1).put()
Child(house=h1).put()
Parent(house=h1).put()
h1 = db.get(h1)
h1.parents.fetch(5)
With the above code, the h1 House instance has 3 entities in its
parents back reference, 2 Parent instances and 1 Child instance.
Instead you would like only the 2 Parent classes to appear in
h1.parents? If that's the case, then you can do something like this
instead:
class Parent(polymodel.PolyModel):
house = db.ReferenceProperty(House, collection_name='parents')
class Child(Parent):
home = db.ReferenceProperty(House, collection_name='children')
h1 = House(address=5).put()
Parent(house=h1).put()
Child(home=h1).put()
Parent(house=h1).put()
h1 = db.get(h1)
h1.parents.fetch(5)
h1.children.fetch(5)
I'm guessing the above would be OK if it is acceptable that the
Child's reference to House is called 'home' instead of the parent
classes 'house'.
Thank you,
Jeff