开发者

What is affected by 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 do开发者_StackOverflow社区c 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?

  • GQL with two tables
  • Google app engine ReferenceProperty relationships


The notion of ownership here is purely semantic, ReferenceProperty fields are only used for navigability.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜