0

Entity A have one-to-many relationship with entity B called points. I have NSPredicate for B. I need to fetch objects of A that have any object of B that satisfies this predicate. How can i do that with one NSPredicate?

I can't do that in two separate operations (first find B, then use them to find A), because i need to keep NSFetchedResultsController for A which must react (call callbacks controllerWillChangeContent, controller:didChangeObject:atIndexPath:forChangeType:newIndexPath: and controllerDidChangeContent) when any object of B is added/changed/removed.

Another note - i getting those predicate on B from other class and i don't know what it contains. Therefore i can't manually insert it in predicate on A.

surfrider
  • 1,376
  • 14
  • 29

1 Answers1

0

If your predicate on B is (for example)

[NSPredicate predicateWithFormat:@"someProp == %@", someValue]

then the predicate to fetch all A objects that have any B object satisfying this property would be

[NSPredicate predicateWithFormat:@"ANY points.someProp == %@", someValue]

The fetched results controller will track changes to the points property of A (adding or removing B objects). However it will not track changes to the properties of the B objects. The reason is that an FRC does not track changes to related objects, compare NSFetchedResultsController with relationship not updating.

Community
  • 1
  • 1
Martin R
  • 529,903
  • 94
  • 1,240
  • 1,382
  • It's right, but i getting those predicate on B from other class and i don't know what it contains. So i can work only with NSPredicate object. Thanks for answer anyway. – surfrider Mar 05 '14 at 13:04