1

I am trying to maintain an application that uses NSCoreData. It has a somewhat complex database, and when I delete an object occasionally it will fail with the following error log:

https://gist.github.com/emilevictor/1faf3c7be7b2ec1876db

I have done a search of stackoverflow and found the following post which seems similar, but did not have any solutions that might apply to me: Core Data Relationships cause save error after delete

Schema

I have confirmed that all of the relationships cascade down, and are matched with a "nullify" on the child object's relationship. Every relationship is also optional.

An example of one of the relationships:

Example one-to-many relationship from Consult to clinical exams.

Community
  • 1
  • 1
Emile Victor
  • 923
  • 1
  • 12
  • 22
  • It's throwing relationship validation errors on a patient object. What is the "an object" that you delete, and what objects are getting deleted with it in the cascade? Does an object like treatmentLaser only have one possible parent? Or do both patient and photos try to cascade delete it in the same cascade? – stevesliva Jun 04 '14 at 17:13

1 Answers1

1

I think I've just had the same problem. The solution is simple, but hard to find.

[context deleteObject:object];
[context validateForDelete:&error]; // returns NO

-

[context deleteObject:object];
[context processPendingChanges];
[context validateForDelete:&error]; // returns YES
OrangeDog
  • 36,653
  • 12
  • 122
  • 207