Reputation: 653
I've got a chat app I'm working on, and I don't undertand very well what relationships I should be using. Here's the setup:
/ Folder 1 \
Account > Mailbox >- Folder 2 - > Message
\ Folder 3 /
As you can see, I'll have a lot of messages, but only one of each of the other entities. What relationships should I set up here so that when a Account
is deleted, it will delete everything going down the line as well? Of course when a message is deleted, it shouldn't delete the account. Ideas?
Upvotes: 1
Views: 169
Reputation: 4897
In your project's data model, you simply need to set the correct 'Delete Rule' on the relationships that are affected.
In this case, it sounds like you're seeking a "Cascade" delete rule. If you were to select your Mailbox entity, and then select it's relationship to messages, and set the delete rule for that relationship as "Cascade" - that will result in the child relations being deleted when the parent (in this case the mailbox) is deleted.
You should definitely checkout the Core Data Programming Guide, which can give you insight in to what each of the different delete rule settings does exactly (personally I think the names are pretty obvious, but still worth a review).
Upvotes: 2