Core data - Deny delete rule causing errors

ios5, xcode

Solution

The deny rule does not work as you are expecting. From Apple's documentation:

If a rule is Deny, then before you delete an object you must remove the destination object or objects from the relationship, otherwise you will get a validation error when you save.

Unfortunately the deny rule does not prevent the deletion, but causes validation error. So you should manually check if the relationship is empty before deletion.

Problem

I have a core data app thats working fine. I'm now trying to add delete rules into a couple of the relationships Entity 1 has a set of Entity 2 If entity 1 is deleted and it has some entity 2 objects, deny delete, otherwise allow. Entity two can be deleted without worrying about Entity 1 I have the relationship on entity 1 set to Deny, and entity 2's set to nullify I'm currently getting an error when trying to delete entity 1 [quote]Unresolved error Error Domain=NSCocoaErrorDomain Code=1600 "The operation couldn’t be completed. (Cocoa error 1600.)" UserInfo=0x1e882f40 {NSValidationErrorObject= (entity: Factory; id: 0x1dda43e0 [/quote] Do i have to do something else to get it working

Original source