views:

50

answers:

1

I have a class:

class AccountTransaction(db.Model):
    account = db.ReferenceProperty(reference_class=Account)
    tran_date = db.DateProperty()
    debit_credit = db.IntegerProperty() ## -1, 1
    amount = db.FloatProperty()
    comment = db.StringProperty()
    pair = db.SelfReferenceProperty()

so, what I want is to make a Save() method which would run the following steps in the transaction:

  • to save AccountTransaction
  • to save paired AccountTransaction (the pair of paired transaction is self - circular reference)
  • to update balances of each of the two Accounts - the account of primary & the account of paired transaction

It is possible that the parents of transactions be the their Accounts, but yet it seems impossible to make an entity group of these entities.

Described in terms of RDBMS, this means that I want that one table has two foreign keys (one entity - two parents). What to do?

At first, I tried not to manage the balances, but it seems to slow to calculate it every time ...

What to do?

+1  A: 

Because your Account entities can't all be in the same entity group, you can't perform an update in a single transaction. There are techniques to do this, particularly in the 'money transfer' case you've encountered - I wrote a blog post about this exact subject, in fact.

Nick Johnson
Yes, that is just what I need. Thank you very much!
manda