在传统的关系数据库中,我有下表:
CREATE TABLE Person(
Id int IDENTITY(1,1) NOT NULL PRIMARY KEY,
MotherId int NOT NULL REFERENCES Person(Id),
FatherId int NOT NULL REFERENCES Person(Id),
FirstName nvarchar(255))
我正在尝试将此表格转换为Google App Engine表格。我的问题在于MotherId和FatherId字段。我尝试了下面的代码,但没有机会。 Python说它不知道对象类型Person。
class Person(db.Model):
mother = db.ReferenceProperty(Person)
father = db.ReferenceProperty(Person)
firstName = db.StringProperty()
有人知道我们如何在Google App Engine表中建模递归关系吗?我如何解决App Engine的限制?
更新 我想稍微扩展一下这个问题......如果我想添加一个孩子的集合怎么办?
children = db.SelfReferenceProperty(collection_name='children_set')
dad.children.append(childrenOne)
我尝试过这个并不起作用。知道我做错了吗?
谢谢!
答案 0 :(得分:10)
我认为你想要SelfReferenceProperty
class Person(db.Model):
mother = db.SelfReferenceProperty(collection_name='mother_set')
father = db.SelfReferenceProperty(collection_name='father_set')
firstName = db.StringProperty()
或者,您可以将母亲与父亲的关系分开。