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?