Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The usual answer is something like "they're required to help maintain data integrity". Here's a specific example.</p> <p>Suppose you have a <code>Department</code> entity and an <code>Employee</code> entity. <code>Department</code> has a to-many relationship <code>employees</code> to <code>Employee</code> but there is no corresponding inverse relationship. A bit contrived, since there are probably good reasons to want to easily look up an employee's department, but I wanted a simple example.</p> <p>Now, suppose I have a specific Department instance named "Department X", which is for all the company's spies. Department X has 7 employees. But then, calamity! Agent 004 is killed by a rival company. So your app deletes Agent 004's <code>Employee</code> instance.</p> <p>Now, how many employees does the <code>Department</code> instance for Department X have?</p> <p>If you haven't been careful about what you're doing, it still has seven employees. But one of them doesn't have any data. Why? Because nobody told the <code>Department</code> instance that one of its employees had gone away, so it thinks nothing has changed. Six regular employees and, I guess, one undead zombie employee.</p> <p>To keep things clean, you also need to get the <code>Department</code> instance for Department X and remove Agent 004's entry from its list of employees.</p> <p><em>If there had been an inverse relationship</em> from <code>Employee</code> back to <code>Department</code>, and you used sane deletion rules, this would have happened automatically. When you deleted Agent 004's instance, Department X's employee list would immediately show only six employees.</p> <p>It's not impossible to get this right without an inverse relationship, but if you do have one, Core Data will look after certain details that help maintain your object graph integrity.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload