I have two entities, one called Group and the other called Contact. They have a many-to-many relationship (with a minimum of one). Thus, at least one contact can belong to one or many groups and at least one group can belong to one or many contacts.
Contact <<-->> Group
Now when I want to update a group I have in my view controller my subclassed NSManagedObject Group available. (@property (nonatomic, strong) Group *selectedGroup;)
Say if group at first has a relationship with 3 contacts, after I updated that group it should have 2 contacts (1 of the original contacts and 1 new contact).
Before update After Update
Group Group
----- -----
ContactA ContactA
ContactB ContactD
ContactC
ContactA should stay intact.
This means that ContactB relationship should be removed from the Group (and also should be deleted from the Contact entity since no other group has a relationship with ContactB)
ContactC should be created.
How would I handle this scenario? I can’t get it to work.
Did you generate model classes for your core data models? If so you should have CoreDataGeneratedAccessors created that look like this in your Group class:
You could then do the following: