Core Data (After Adding Unique Constraint) : annot

2020-06-12 06:29发布

问题:

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

Properties: CDEvent CDMeeting

CDMLCheckin

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 :(

回答1:

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 ?