开发者

Need beginner's explanation for the difference between using a parent-entity relationship versus ReferenceProperty

In regards to this statement in Google's app-engine doc:

"Only use entity groups when they are needed for transactions. For other relationships between entities, use ReferenceProperty properties and Key values, which can be used in queries."

can someone give an example of a query of say getting all the players that are member of the same team. also say that this set of players for each team never changes, but characteristics of the team such as uniforms, wins, losses and sala开发者_StackOverflow中文版ries change and effect each player...in such a case does this mean that there are or are not 'transactions' involved.

How would you code a query asking for all the players of a certain team?


A transaction has nothing to do with how the data is organised, it's a specific database operation. Within a transaction you can do multiple reads and writes, and the whole thing succeeds or fails together. The limitation is that all the entities affected must be in the same group. If you were using transactions, then you'd know you were: looking up team data doesn't make it a transaction.

If your players use a reference property to specify the team, you'd query that in GQL with WHERE team=KEY('Team', <id>), <id> being the id of the team entity. Alternatively, you can do this:

for player in team.player_set:
    # iterating over the players in the team...

When the Player kind has a reference property to the Team kind, teams automagically gain this player_set collection (well, actually it's a Query) which you can iterate. It's called a "back-reference"

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜