If a Team has a lot of Games you don't have enough time to delete them
all in 30 seconds.

You must use a method that always work, even in the event that the
datastore is giving troubles or is in maintenance (no write or delete
possible).

What you could do is mark the Team as being deleted, add an extra
field to the model.
Give the operator feedback that the Team is successfully marked as
deleted. Read the Team object back and check the deleted attribute.

When you want to create a Game filter for teams not marked for delete.

With a cron job:

1) Find a Team marked for delete.  markedTeam =
Team.all().filter('deleted =',True).get()
2) Find Games for this Team, in team1 or team2 attribute, fetch at most 10 games
3) if Games found: delete Games
   if no Games Found: delete Team

This way you will eventually delete all the Games and the Team.

2009/4/13 GMailingList <gappengin...@gmail.com>:
>
> Ok maybe I don't absolutely need it to delete a team but what about...
>
> 1) when I'm creating a new game - team1 or team2 could be deleted as
> I'm creating a new game, then the game will have a team that does not
> exist
>
> OR
>
> 2) for arguments sake, I need the deletion of a team (and all the
> games it's in) to be atomic.  What you're suggesting can fail at
> anywhere between 1 and 4.
>
>
> On Apr 12, 4:35 pm, djidjadji <djidja...@gmail.com> wrote:
>> Start with answering the question: Do I need a transaction?
>>
>> I don't think you need it to delete a team.
>>
>> Every Team and every Game are root entities, no child objects.
>>
>> When you want to delete a Team
>>    1) find all Games that have the Team in attribute team1
>>    2) delete these Games, maybe delete in groups of 10 to 20 per request
>>    3) find all Games that have the Team in attribute team2
>>    4) delete these Games, maybe delete in groups of 10 to 20 per request
>>    5) delete the Team object
>>
>> You can use the method from [1] to delete the Games
>>
>> [1]http://code.google.com/appengine/articles/update_schema.html
>>
>> 2009/4/13 ae <gappengin...@gmail.com>:
>>
>>
>>
>> > Does anybody else find transactions very restricting?  How do I solve
>> > this problem?  Here is my data model...
>>
>> > Team(db.Model):
>> >  name = db.StringProperty()
>>
>> > Game(db.Model):
>> >  team1 = db.ReferenceProperty(Team, collection_name='game1_set')
>> >  team2 = db.ReferenceProperty(Team, collection_name='game2_set')
>>
>> > ... if I delete a team, I want to delete all the games associated with
>> > it as well so I need to put the delete operation in a transaction.
>> > But how would I setup the entity group?
>>
>> > setup 1) Team as parent of Game - but there can be only 1 parent and
>> > team1 and team2 should both be parents - DOESN'T WORK
>> > setup 2) Game as parent of Team - then that would mean each team can
>> > only play 1 game?  DOESN'T WORK
>> > setup 3) create a 3rd entity and let that be the parent of both Team
>> > and Game - but then all teams and games would be in the same entity
>> > group - is this my only option?
>>
>> > Thanks.
>>
>>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To post to this group, send email to google-appengine@googlegroups.com
To unsubscribe from this group, send email to 
google-appengine+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to