views:

102

answers:

1

I have an issue with creating a transaction. I get an error back that the objects are not in the same entity group.

I have a type called Relationship and I need to create a two way relationship between two parties.

def _transaction():
    relationship1 = Relationship(firstParty = party1, secondParty = party2)
    relationship2 = Relationship(firstParty = party2, secondParty = party1)
    db.put([relationship1 , relationship2 ])
db.run_in_transaction(_transaction)

Both of the party objects are the same type. The business rule dictates both records need to be persisted or it needs to fail. The error comes from the party objects. the properties firstParty and secondParty are Reference Properties. How can i perform a transaction on this business rule?

+3  A: 

You need to understand entity groups before you can effectively work with transactions in app engine. Start here. In short, only entities (what you call records) in the same entity group can be involved in a transaction. By default, entities are created in their own group, so you will not be able to perform a transaction on them.

Peter Recore
I had read the documentation on entity groups but had been viewing as if an object was an entity group, more of a horizontal relationship than vertical. I see now that an entity is a record and that its parents and children make up the group. that does make sense. Hopefully I have it correct this time. Thanks again.
Jeremy B.
Understanding is half the battle. The next challenge is figuring out how to structure your data so that you can have small entity groups but still perform transactions when you need to.
Peter Recore