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.
精彩评论