Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><br/>This is a great question.<br/><br/> ButFirst thing first:<br/>It clearly state in the <a href="https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CoreData/Articles/cdRelationships.html" rel="nofollow">documentation</a>:<br/></p> <blockquote> <blockquote> <p>"Important: You must define many-to-many relationships in both directions—that is, you must specify two relationships, each being the inverse of the other. You can’t just define a to-many relationship in one direction and try to use it as a many-to-many. If you do, you will end up with referential integrity problems."</p> </blockquote> </blockquote> <p>Never the less, Lets describe the issue (resulting database)<br/> When defining a to-many relationship, the resulting database does not add an additional table to map the relationship.<br/> It only sets a property on the entity at one end of the to-many relationship equal to the last item that referenced it.<br/></p> <p>Example:</p> <p>Model:<br/> Entity: Department<br/> Relationships: NONE<br/> Properties: name (string)<br/></p> <p>Entity: Employee<br/> Relationships: departments (to-many,no-action)<br/> Properties: name<br/></p> <p>Resulting Database:<br/> ZDEPARTMENT:<br/> Z_PK<br/> Z_ENT<br/> Z_OPT<br/> Z2DEPARTMENTS (int)<br/> ZNAME<br/></p> <p>ZEMPLOYEE:<br/> Z_PK<br/> Z_ENT<br/> Z_OPT<br/> ZNAME<br/></p> <p>This structure will obviously result in data inconsistency.<br/></p> <p>The solution will be to hold an entity: <code>DepartmentEmployee</code> modeling the to-many relationship in both directions but one of them would be unidirectional (Department -> DepartmentEmployee):<br/></p> <p>DepartmentEmployee:<br/> Relationships: department (to-one,no-action), employee (to-one,nullify)<br/></p> <p>and you will have to maintain the table upon deletion of a department object.</p> <p>Hope this made some sense :)</p>
    singulars
    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. 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.
 

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