5

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?

Community
  • 1
  • 1
Noam Solovechick
  • 1,127
  • 2
  • 15
  • 29
  • @vikingosegundo: You are right. It is my fault that I did not search for a duplicate before posting an answer, and I did not see your comment before hitting "Post". – Martin R Jan 19 '13 at 12:34

1 Answers1

17

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.

Martin R
  • 529,903
  • 94
  • 1,240
  • 1,382
  • Thank you! I knew there was a "duplicate" (I found it) but I didn't understand why do I have to inverse. Now I got it, your answer is really clear. – Noam Solovechick Jan 19 '13 at 13:14