ReferenceProperty 会影响什么?
参考这两个问题(参见下面的链接)和 Google AppEngine 文档,我有点困惑:
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
来源:Google
文档示例表明该对象具有ReferenceProperty
是“所有者”对象,它(可以)具有作为关系项的对象。
下面的链接显示了反之亦然: 具有ReferenceProperty 的对象是“拥有的”对象。 现在我的问题是,什么是正确的,或者我遗漏/误解了 ReferenceProperty
的哪些方面?
In reference to these two questions (see links below) and the Google AppEngine doc, I got a little bit confused:
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
Source: Google
The doc example indicates that the object which has the ReferenceProperty
is the "owner" object, which (can have) has such an object as relational item.
The links below show it vice-versa:
The object which has the ReferenceProperty
is the "owned" object.
Now my question is, what is right, or what aspect of the ReferenceProperty
am I missing/misunderstanding?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这里的所有权概念纯粹是语义性的,ReferenceProperty 字段仅用于导航性。
The notion of ownership here is purely semantic, ReferenceProperty fields are only used for navigability.
引用仅意味着引用性(如果您愿意的话,可以是“具有”关系),而不是所有权。在您的示例中,一个故事“有一个”作者。另一种思考方式与在 OO 中使用变量来引用对象的方式相同。
References imply only referentiality - a "has a" relationship, if you like - not ownership. In your example, a Story "has an" Author. Another way to think about it is in the same way you would use a variable to refer to an object in OO.