I have a basic Core data model like this:
Class
-Class Name (string)
Relationship: HasDetails (to many) -to Details
Details
-Number (int)
-Name (string)
Relationship: IsPartOfClass -to Class
I have two table views, one for “Class” and one for “Details” and have all the bindings set up, however, when I add a new object to Details it shows up for all the Classes, when I want it to show up for only one, the selected one
There’s a lot of information missing here and your description of your entities is confusing. I strongly urge you to take the time to provide far more detail in the future.
It sounds as though you have a Class <—->> Details (one-to-many relationship: a Class has many Details and a Details has one Class). Is that right?
Assuming Class’ details relationship is called “details” and Details’ class relationship is called “class”, and that everything is set up properly in your Managed Object Model (inverse relationships are almost always the right thing to do), you’d want the following:
By doing this, calling the Details array controller’s -add: -insert: and -delete: (or is it “-remove:”?) methods (such as from a button) will automatically treat the relationship correctly (will add the new “Detail” instance to the selected “Class” instance’s details set.
Make sure you bind the add/insert/remove buttons’ enabled states to the array controller’s “canAdd” and “canRemove” (or is it “canDelete”?) properties so they’re disabled if there’s no selection in the required places.