Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should have an inverse in Core Data [duplicate]

Possible Duplicate:
Does every Core Data Relationship have to have an Inverse?

I have the following entities with the relationships: enter image description here

A CombinedSH must have a Subject and a StudyHour.
A Subject must NOT have a CombinedSH.
A StudyHour must NOT have a CombinedSH.

In my app, it does not make sense that a Subject / a StudyHour will have a CombinedSH. The problem is that Xcode gives me the following warnings:

warning: Misconfigured Property: CombinedSH.studyHour should have an inverse.

warning: Misconfigured Property: CombinedSH.subject should have an inverse.

So Xcode says that there should be an inverse - but in my app it doesn't make sense. What should I do?

like image 361
Noam Solovechick Avatar asked Jan 19 '13 12:01

Noam Solovechick


1 Answers

You can define the inverse relationship from Subject to CombinedSH and mark it as "optional". Then a "Subject" need not have a "CombinedSH".

Doing so makes Xcode happy, but has also another advantage. Assume you have objects

CombinedSH *csh1;
Subject *s1;

and

csh1.subject = s1;

What happens, if s1 is deleted? Without inverse relationship, csh1.subject would point to some deleted object.

But if you define the inverse relationship, and set the "Delete Rule" of that relationship to "Nullify", then deleting s1 automatically sets

csh1.subject = nil

and therefore subject cannot point to a deleted object anymore.

like image 99
Martin R Avatar answered Sep 23 '22 02:09

Martin R