Note that there are some explanatory texts on larger screens.

plurals
  1. PONSFetchedResultsController with relationship not updating
    primarykey
    data
    text
    <p>Let's say I have two entities, employee and department. A department has a to-many relationship with employee, many employees can be in each department but each employee only belongs to one department. I want to display all of the employees in a tableview sorted by data that is a property of the department they belong to using an NSFetchedResultsController. The problem is that I want my table to update when a department object receives changes just like it does if the regular properties of employee change, but the FetchedResultsController doesn't seem to track related objects. I've gotten passed this issue partially by doing the following:</p> <pre><code>for (Employee* employee in department.employees) { [employee willChangeValueForKey:@"dept"]; } /* Make Changes to department object */ for (Employee* employee in department.employees) { [employee didChangeValueForKey:@"dept"]; } </code></pre> <p>This is obviously not ideal but it does cause the employee based FRC delegate method didChangeObject to get called. The real problem I have left now is in the sorting a FRC that is tracking employee objects:</p> <pre><code>NSEntityDescription *employee = [NSEntityDescription entityForName:@"Employee" inManagedObjectContext:self.managedObjectContext]; NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"department.someProperty" ascending:NO]; </code></pre> <p>This works great and sorts the employees correctly the first time it's called, the problem is that when I make changes to a departments someProperty that should change the sorting of my employee table nothing happens. Is there any nice way to have my employee FRC track changes in a relationship? Particularly I just need some way to have it update the sorting when the sort is based on a related property. I've looked through some similar question but wasn't able to find a satisfactory solution.</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.
 

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