Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Core Data (After Adding Unique Constraint) : annotation: repairing missing delete propagation for to-many relationship

This issue started occurring after we added Unique key i.es Constraint.

Frequently updating Meeting managed object deletes the event managed object which has a to-one inverse relationship from meeting managed object.

Error CoreData: annotation: repairing missing delete propagation for to-many relationship meetingList on object 0x60c00009c4d0 (0x60c000621e40 ) with bad fault 0x60800009ac20 (0x60800023a360 )

Data Model

I have three entities in my core data model i.es

(CDEvent, CDMeeting, CDMLCheckin) .

Entity Properties and Relationship as described below:

Relationship enter image description here

Properties: CDEvent enter image description here CDMeeting enter image description here

CDMLCheckin enter image description here

Unique Constraint:

  • CDEvent entity has eventUUID as unique constraint.
  • CDMeeting entity has meetingUUID as unique constraint.

Relationship

  • CDEvent <->>CDMeeting
    • From CDEvent to CDMeeting is to-many relationship with delete rule cascade, inverse relationship from CDMeeting to CDEvent is to-one with delete rule nullify.
  • CDEvent <->>CDMLCheckin
    • From CDEvent to CDMLCheckin is to-many relationship with delete rule cascade, inverse relationship from CDMLCheckin to CDEvent is to-one with delete rule nullify.

Full Description : https://docs.google.com/document/d/1y2DQhBBLqjAP9eWbx5YpQhH7oVigxT_mcJDnPLlOMtQ/edit?usp=sharing

Note

  • If i remove Unique Constraint eventUUID from CDEvent everything works fine.

Please help us here as we are struck from more than a week :(

like image 361
IamAnil Avatar asked Mar 06 '18 11:03

IamAnil


1 Answers

I hope I can help, having a unique constraint with To-Many Relationship Entities you need to keep some points in mind

  • Use Inverse Relationship of every CoreData relation
  • Unique Constrains Attributes should never be Optional

When you create NSManagedObjectContext make sure you set MergePolicy.

[_context setMergePolicy: mergePolicy];

  • NSMergeByPropertyStoreTrumpMergePolicy

  • NSMergeByPropertyObjectTrumpMergePolicy

  • NSOverwriteMergePolicy

Also could you try changing the nullify delete rule to no action ?

like image 88
Ionescu Vlad Avatar answered Nov 07 '22 01:11

Ionescu Vlad