1

基于 PolyModel 的类可以用作 SelfReferenceProperty 吗?

我有以下代码:

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

我执行此代码并通过开发服务器的管理界面检查数据存储。父实例保存到数据存储区 class = 'BaseClass,ParentClass',但子实例未保存。浏览器没有错误输出(调试已打开),我的应用程序的启动器日志中没有任何内容。

这可能吗?

4

1 回答 1

0

说我在这里什么都没改变是骗人的。我实际上不得不将“parent”属性更改为“parent_ref”。在我从 SelfReferenceProperty 更改为 ReferenceProperty(Parent, collection_name = 'children') 之前,这些引用也没有像我预期的那样工作

但最终结果是多态自引用确实有效。

于 2010-04-14T01:42:24.363 回答