0

I have a question around what entities I should have for Core Data in a very simple personal financial application on iOS.

I have an 'Account' entity which has many 'Transaction' entities which contain details like the date of transaction, the amount, the category and the payee etc.

My question is how should I model a 'transfer' transaction where the transaction will apply to more than one account, i.e debited from account A and credited to account B.

I understand the principles of double entry accounting but this is probably more than I need for this app. I just want a simple way of modelling a transfer between 2 accounts?

Any ideas?

Thanks

MPelletier
  • 16,256
  • 15
  • 86
  • 137
  • Why not just insert two (or more) records in the account entity so long as the "total" is the same. From a simple stanpoint enter in the details and have from account and two account fields if they fill both in, then 2 entries are made fill in 1 then only 1 entry is made. – xQbert Apr 18 '12 at 18:32
  • Thanks for the response. Would I not need a single transfer entity to represent the transfer, that way if it were deleted from one account it would automatically be removed from the other account? – CpBulletSponge Apr 18 '12 at 19:30
  • Why don't just use nullify relationship for that purpose?) – Nikita Pestrov Apr 18 '12 at 20:36

1 Answers1

0

You will want to use a many-to-many relationship between your Transaction and Account entities.

Jeff Wolski
  • 6,332
  • 6
  • 37
  • 69
  • If a transaction has many accounts, i.e. 1 for the 'from' account and 1 for the 'to' account, it only has a single 'amount' attribute so it would be debited from both accounts rather than credited to the 'to' account? – CpBulletSponge Apr 19 '12 at 06:34