NSFetchedResultsController does not get refreshed for added relationship
||Date Originated:||May 26, 2012|
Adding a relationship after a save does not update NSFetchedResultsController that uses a predicate containing this relationship.
Create Entity -> Save Context -> Add Relationship -> Save Context => does not show object in fetched results controller
Create Entity -> Add Relationship -> Save Context => does show object
Steps to Reproduce:
A NSFetchedResultsController is based on a predicate where in a many-to-many relationship one element in the searches relationship needs to be a certain one. i.e.
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(isRetweet == NO) AND (%@ IN searches)", _search];
Create a new entity on a background queue that has the same store coordinator as the main thread MOC so it can write to disk. Save the background MOC which will merge the changes via change notification into the mainMOC. Releationship is not yet set, so the fetched results are empty.
Now set the relationship, this would now qualify the fetched results to contain this new object. But it does not show up.
Leaving the view controller using the fetched results controller and returning has the items show up.
Adding a relationship should trigger the expected update of the fetched results controller having a predicate to include these objects.
The update is not triggered if the adding of the relationship is done after the first save of the new managed object. Only setting the relationship and then saving does not trigger anything on the fetched results controller.
Notes: Obviously the workaround is to have all the changes of the new object occur together so that the setting of other attributes made the object "dirty" and cause the notification. But this is confusing nevertheless.
Reports posted here will not necessarily be seen by Apple.
All problems should be submitted at bugreport.apple.com before they are posted here.
Please only post information for Radars that you have filed yourself, and please do
not include Apple confidential information in your posts. Thank you!