Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Have you considered doing away with the relationship entirely and programmatically managing the foreign key on employee? </p> <p>If you have a UI which sets the property from a list of existing Departments (a pick list, etc.) you can simply take the primary key from that list and assign it as the <code>departmentID</code> property on your Employee.</p> <p>You should then be able to implement a <code>validateDepartmentID:error</code> method on your Employee object which checks that the given <code>departmentID</code> is valid (i.e. is in a fetched list of departments) and/or is not null so that you maintain referential integrity between the Employee and Department.</p> <p>When fetching the list of Employees in a Department, you can either use fetched properties or add an instance method to the Department which returns an instance of <code>NSFetchedResultsController</code> containing the Department's employee list.</p> <p>The only other thing you'd need to do is inject some deletion logic in your Department class (likely on <code>-prepareForDeletion</code>) to update the <code>departmentID</code> on any affected child records. That one depends on your business logic.</p> <p>The <a href="https://developer.apple.com/library/ios/#documentation/Cocoa/Reference/CoreDataFramework/Classes/NSManagedObject_Class/Reference/NSManagedObject.html#//apple_ref/doc/uid/TP40003607" rel="nofollow">Apple docs on property validation</a> cover <code>-prepareForDeletion</code> and <code>-validateValue:forKey:error</code> if you're not familiar with them.</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. This table or related slice is empty.
    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