views:

48

answers:

1

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 salaries 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: 

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"

Steve Jessop
so for us to call something a 'transaction' then some sort of write is involved. What if you want to plan for daily updates ('transactions') of some attribute value for some subset of teams, and you would like this change to pass down to the corresponding players........so for this type of transaction, I dont understand how modeling Team entities as a parent-entities of Player entities is significantly different than just using ReferenceProperty for those player attributes we want linked to their team membership?
newguy