Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When does the DENY delete rule in Core Data actually deny deletion of an object?

An Employee has an inverse relationship to it's Department and vice versa. The Employee entity has an Relationship called department, and it has a DENY delete rule. Employee shall be deleted. Now: Does DENY actually deny deletion of employee, because department is still referencing a Department? Or does it mean that a Department can't be deleted because an Employee is referencing it?

like image 386
dontWatchMyProfile Avatar asked Jun 13 '10 09:06

dontWatchMyProfile


People also ask

What is delete rules in core data?

A delete rule defines what happens when the record that owns the relationship is deleted. A delete rule defines what happens when the record that owns the relationship is deleted. Select the notes relationship of the Category entity and open the Data Model Inspector on the right.

What is the function of a deletion rule?

Setting the Delete Rule to Delete guarantees that when a record of the main Entity is deleted, all the associated records in the related Entities are also deleted.

How do I delete all core data?

One approach to delete everything and reset Core Data is to destroy the persistent store. Deleting and re-creating the persistent store will delete all objects in Core Data.


1 Answers

Deletion rules are always looked at from the point of view of the object they are being set on so I think you have your description backwards. What you would want in that situation is:

  • Employee can be deleted any time and it's relationship to it's department should be nullified. This means you set the department relationship to nullify.

  • Department can only be deleted if it no longer has any employees. This calls for a deny rule which would prevent the deletion of a department if it contains any employee records at all.

Your description implied the reverse which would mean that the employee could not be deleted unless it's department was set to nil. While certainly possible, it seems unnecessary.

like image 190
Marcus S. Zarra Avatar answered Oct 06 '22 13:10

Marcus S. Zarra