Reputation: 14687
I have a question about the Core Data Model and the Cascade Delete Rule.
My Core Data Model is this one:
As you can see the User Entity has a "To Many" Relationship with the Orders Entity. Also the Orders Entity has a parent entity called Cuisines, as each Order needs to be from a list of available Cuisines.
The User To Orders Relationship delete Rule is Cascade (the inverse is nullify) as I want all orders to be deleted if the user object is deleted.
My question is what happens with the Cuisines Entity if I delete the User?
The Cuisines should be available for all orders placed for other Users as well, so it must persist. Will it be also deleted?
If yes, how should I create my model and set the delete rules to avoid this?
Upvotes: 1
Views: 288
Reputation: 21536
Specifying Cuisines
as the parent entity for Orders
means that each Orders
object is a Cuisine
- albeit a specific "type" of Cuisine
. Each Order
has three attributes: numOfOrders
, rating
and name
. When you delete an Order
(albeit through a cascade rule), you are deleting one object with all three attributes - there isn't a separate Cuisines
object to be deleted.
But you want each order to be from a list of available cuisines. So replace the parent/subentity link between Orders
and Cuisines
with a relationship. Each Cuisine
can be related to several different Orders
, so the relationship would be to-many. Conversely, each Order
relates to only one Cuisine
, so the inverse relationship will be to-one. When you delete an Order
, you want the related Cuisines
to remain (for use in other Orders
) so the delete rule would be "nullify".
Upvotes: 0