Reputation: 33
Been trying to understand how to model a circular core-data many-to-many relationship in Xcode 4.2. In SQL I would be using mapping tables and customize my SQL expressions to give me the right data, but in Core data I can’t seem to understand how to get his to work properly. I have 3 entities which are all related to each other:
My links are:
What is the best way to model this using Core data and which entites, with which relationships between them would be most adequate? Would you use mapping tables between these 3, or just assign the correct relationships?
Any help would be highly appreciated as I can't seem to figure this out....
EDIT: Thank you very much for the fast feedback. Unfortunately I can't upload my data model as I am new to this site and not allowed to post any images.
To read the data I am currently only using a Predicate like this:
predicate = [NSPredicate predicateWithFormat:@"personPartOfRoles == %@", myRole];
What I can't seem to figure out is how to maintain this object graph to add or remove persons from roles. I have assumed I need to load up the entire graph in memory and somehow find only the correct entities to map in.
Upvotes: 3
Views: 549
Reputation: 46718
Department <<--->> Role (roles to departments)
Department <<--->> Person (departments to people)
Role <<-->> Person (roles to people)
Make each relationship have an inverse.
Remember that Core Data is an object graph that can persist to a database. Treat it like an object graph.
Upvotes: 3
Reputation: 14694
Just assign the correct relationships in your entities.
If you are going to use Core Data it is important to ignore the fact that you are storing in SQLite. The storage is simply a behind the scenes implementation detail (as coredata is capable of storing in XML or in memory) that you can forget about.
Upvotes: 3