Reputation: 1305
I have two entities Account and Transaction. Following conditions are applicable for the db.
Each Account has different transactions
allTransactions
has to many relationship with Transaction
table
Each transaction related to one account (Debited from Account
/ Credited To Account
), accounts
has to one relationship with Account
Table.
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
Upvotes: 0
Views: 96
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