user2053760
user2053760

Reputation: 1703

coredata many to many relation with fetchedResultController

I have two entities A and B, and their relationship is many to many. The class of the entities are like:

A NSSet *toB

B NSSet *toA

Now I have an object of A and I can get all related B objects by using the "toB" set. Since I need to re-order the B objects, I have to use an array to contain all the B objects, and the problem is there would be thousands of Bs, and I am worried about the array would occupy to much memory. So I was wondering if I can use NSfetchedResultController to fetch all the related B objects. The question is how I should do this? By using sort of predicate to fetch? Thank you.

Upvotes: 0

Views: 30

Answers (1)

Mundi
Mundi

Reputation: 80271

Use B as the entity for the fetched results controller. Add a sort descriptor.

To restrict your Bs to one A's Bs, add a predicate such as this:

NSPredicate(format: "%@ in toA", anAObject)

Upvotes: 1

Related Questions