How to deal with many to many relationships with NSFetchedResultsController?
- by Phil Yates
OK so I have two entities in my data model (let's say entityA and entityB), both of these entities have a to-many relationship to each other.
I have setup a NSFetchedResultsController to fetch a bunch of entityA. Now I'm trying to have the section names for the tableview be the title of entityB.
sectionNameKeyPath:@"entityB.title"
Now this causes a problem, where by the section name returned from that relationship appears to be ({title1}) or ({title1,title2...titleN}) obviously depending on how many different entityB's are involved. This doesn't look great in a tableview and doesn't group the objects as I would like.
What I would like is a section per entityB title with entityA appearing under each section, under multiple sections if necessary. I'm at a loss as how I am supposed to achieve this whether I need to update the predicate to get the entity to appear multiple times or whether I need to update the section and header functions to do some processing as the controller loops through the objects.
Any help is appreciated :)
Thanks