views:

79

answers:

1

Is a PolyModel-based class able to be used as a SelfReferenceProperty ?

I have the below code :

class BaseClass(polymodel.PolyModel):
    attribute1 = db.IntegerProperty()
    attribute2 = db.StringProperty()

class ParentClass(BaseClass):
    attribute3 = db.StringProperty()

class ChildClass(BaseClass):
    parent = db.SelfReferenceProperty(collection_name = 'children')


p = ParentClass()
p.attribute1 = 1
p.attribute2 = "Parent Description"
p.attribute3 = "Parent additional data"
p.put()

c = ChildClass()
c.attribute1 = 5
c.attribute2 = "Child Description"
c.parent = p.key()
c.put()

I execute this code and check the datastore via the development server's admin interface. The parent instance is saved to the datastore class = 'BaseClass,ParentClass', but the child is not. There is no error output to the browser (debug is turned on) and nothing in the launcher's log for my app.

Is this possible to do ?

A: 

It's a lie to say I changed nothing here. I actually had to change "parent" attribute to "parent_ref". Also the references didn't work as I expected until I changed from SelfReferenceProperty to ReferenceProperty(Parent, collection_name = 'children')

But the end result is that polymorphic self-referencing does work.

rvandervort