Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to avoid Core Data warning "Entity should have an inverse relationship"?

I have a model graph, where there is several entities that have one to many relationship with other entity.
It means that inverse relationship should be one to many, but that is impossible.

The core data works well without inverse relationship; the only thing that drives me crazy is warnings:

Entity should have an inverse relationship

Does anybody know how to avoid these specific warnings?

like image 607
Remizorrr Avatar asked Feb 08 '14 05:02

Remizorrr


1 Answers

Inverse Relationships

Most relationships are inherently bi-directional. If a Department has a to-many relationship to the Employees that work in a Department, there is an inverse relationship from an Employee to the Department. The major exception is a fetched property, which represents a weak one-way relationship—there is no relationship from the destination to the source (see “Fetched Properties”).

You should typically model relationships in both directions, and specify the inverse relationships appropriately. Core Data uses this information to ensure the consistency of the object graph if a change is made

Reference in Apple documentation

As a general rule, a one-to-many relation has a many-to-one inverse. In case you want to define a many-to-many relationship, you simply define one relation as to-many and its inverse as a to-many as well.

like image 59
codercat Avatar answered Nov 13 '22 12:11

codercat