-1
class Author(db.Model):
    name = db.StringProperty()

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

story = db.get(story_key)
author_name = story.author.name

author = db.get(author_key)
stories_by_author = author.story_set.get()

As is known; using ReferenceProperty is good solution for data relationship as exampled above. So; For example, we have a large amout of row in our "Author" and "Story" entities(tables). And after many years we deleted "Author" entity or replaced name propery to another name. Naturally; our app sholud throw error. Can this situation (managing code) reasonable or is performing relationships manually good? Is there any alternative model for this case?

4

1 回答 1

0

那是数据存储提供的工具。如果你想要更健壮的东西,你可以构建一个带有析构函数的类,这些析构函数总是检查它们的 ReferenceProperties 并清理它们。

这有点像问指针是否是一件坏事,因为您可能会泄漏内存并留下悬空指针。是的,但在某些语言中,这是可用的基本工具。如果您想要更安全的东西,请围绕它构建一个包装器。或使用其他语言(如 Cloud SQL)。

于 2012-10-06T15:31:29.100 回答