views:

40

answers:

1

I have entity Unit and Tag, each with to-many relation to other.

I am using NSFetchedResultsController to manage the data. What I need is to return distinct Unit object into NSFetchedResultsController for condition Tag.show == YES. I'm not sure how to feed all this to NSFetchedResultsController. Set entity to Unit or Tag, how to build predicate for it.

Example:

I have 6 Tag objects tag1...tag6 and 3 Unit object unit1, unit2, unit3. tag1, tag2 are pointing to unit1, tag3, tag4 to unit2. tag1...tag4 met show == YES condition. So I want finally to get uni1 and unit2 into NSFetchedResultsController.

+2  A: 

Do a fetch on the Unit entity with a predicate of "ANY Tag.show==YES".

That will return any Unit instances that has one or more related Tag instances with show==YES. Fetches return distinct objects so you don't have to do anything else.

TechZen
@TechZen: I just discovered same and good to see your post! You are always helpful, thank you!
Michael