【问题标题】:In Google App Engine, how do I use reference properties between two entities that reference each other?在 Google App Engine 中,如何在相互引用的两个实体之间使用引用属性?
【发布时间】:2010-02-17 16:10:45
【问题描述】:

如果我有两种相互引用的模型,无论我首先尝试定义的哪一个都表示它无法识别引用的其他类型(因为它在文件中进一步定义)。例如:

class Author(db.Model):
    most_recent_book = db.ReferenceProperty(Book)

class Book(db.Model):
    author = db.ReferenceProperty(Author)

这将声称引用的“图书”模型无法识别。如果我翻转订单,我会遇到同样的问题(除了它会说“作者”无法识别)。我该如何解决这个问题?

【问题讨论】:

    标签: google-app-engine referenceproperty


    【解决方案1】:

    您可以在不声明类型的情况下使用 ReferenceProperty,如 AppEngine Tips 中的this article 中所述

    【讨论】:

    • 感谢亚当的提示,我已经用 ndb 试过了,效果很好。你知道这是否是最好的方法吗?这似乎有点hacky...
    • 被否决,因为链接已损坏,使答案无用:(
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-11-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多