Say, we have 2 entities : Parents and children.
When a parent is deleted, then all the children are erased too.
Great.
Now we have entities called lover.
Each individuals can “love” many other individuals and be loved by many.
What happen if an individual deleted?
Does cascade delete:
- Don’t work at all?
- Delete you when the last person that love you is deleted?
Or what?
I think, that you shouldn’t use cascade with to-many this way, because, as it deletes all the lovers of the object you delete, it may go further and further and delete the whole database.
So the better approach for you is to have a intermediate (“join”) entity, for example, loverInfo.
Here’s, how the Apple suggest you to do that, based on the friends relationship.
To establish a friendship from one person to another, you have to
create an instance of FriendInfo. If both people like each other, you
have to create two instances of FriendInfo
To break a friendship, you must delete the appropriate instance of
FriendInfo.
person is removed from the store, then the FriendInfo instance
becomes invalid, so must also be removed.
be optional—an instance of FriendInfo is invalid if the source or
friend is null.