与 Google App Engine 和 BigTable 的递归关系
在经典的关系数据库中,我有下表:
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)
我尝试了这个,但它不起作用。 知道我做错了什么吗?
谢谢!
In a classic relational database, I have the following table:
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))
I am trying to convert this table into a Google App Engine table. My issue is with the fields MotherId and FatherId. I tried the code below, but no chance. Python says that it doesn't know the object type Person.
class Person(db.Model):
mother = db.ReferenceProperty(Person)
father = db.ReferenceProperty(Person)
firstName = db.StringProperty()
Does someone know how we can model a recursive relationship in a Google App Engine table? How could I work around the limitation of App Engine?
UPDATE
I want to expand the problem a little bit... What if I wanted to add a collection of children?
children = db.SelfReferenceProperty(collection_name='children_set')
dad.children.append(childrenOne)
I tried this and it doesn't work. Any idea what I am doing wrong?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您需要这里的 SelfReferenceProperty
或者,您可以将母亲和父亲关系放在不同的类中。
I think that you want SelfReferenceProperty here
Alternatively, you can put the Mother and Father relations in separate classes.