iPhone Guy
iPhone Guy

Reputation: 1305

How to map relationship between these entities -Coredata iOS

I have two entities Account and Transaction. Following conditions are applicable for the db.

  1. Each Account has different transactions allTransactions has to many relationship with Transaction table

  2. Each transaction related to one account (Debited from Account/ Credited To Account), accounts has to one relationship with Account Table.

  3. Amount can be transferred between the accounts. (Transaction)

Problem: How can i relate the transaction table with Account Table for the above (point 3) condition

My Coredata Structure

enter image description here

Upvotes: 0

Views: 96

Answers (1)

Mundi
Mundi

Reputation: 80265

If you are transferring an amount from one account to another account, you need references to two accounts.

Transaction 
  - fromAccount <<--> Account
  - toAccount   <<--> Account

On the Account side you will need two inverse relationships.

Account
  - outgoing <--->> Transaction
  - incoming <--->> Transaction

So you do not need the property accounts. (It is also confusing to name a to-one relationship in the plural.) Similarly, you will not need allTransactions.

Upvotes: 1

Related Questions