Re: Core Data: Custom to-many relationship setter not being invoked
Re: Core Data: Custom to-many relationship setter not being invoked
- Subject: Re: Core Data: Custom to-many relationship setter not being invoked
- From: Quincey Morris <email@hidden>
- Date: Tue, 23 Feb 2010 10:19:20 -0800
On Feb 23, 2010, at 01:20, Ken Tabb wrote:
> Adding is via a button going to an Employee array controller's -add. In the interface there are 2 array controllers (1 for Departments, 1 for Employees). The Employees controller is set to use the selection in the Departments controller (i.e. showing the subset belonging to the selected dept).
You haven't actually told us the whole story. Calling the Employee array controller's 'add:' method causes a new Employee object to be created with default attributes and no relationships -- no Department. That means the code to assign it to a Department is elsewhere.
> Adding and deleting Departments and Employees is fine (everything gets hooked up / added / deleted properly), and if I look in the XML Core Data store, all is well. It's just my custom accessors (the 4 mentioned below) don't get used, whereas -setEmployees does.
If you did not try this already, set a breakpoint inside 'setEmployees:'. When you hit it, type the debugger command 'po [self class]' in the Xcode console window to find out the actual class of the Department object.
> Do you reckon it's because the adding is happening from the Employee side of things rather than the Department side of things? Shouldn't both sides have their accessor methods called (thanks to the inverse relationship)?
There are no "sides" as far as adding objects is concerned. There are "sides" when you talk about establishing relationships, but we don't know how you do this yet. Also, the puzzle here is not whether accessor methods are being called, but which accessor methods are being called. The setter, for a to-many property, is kind of the worst-case fallback accessor, and KVC should prefer the more nuanced add/remove accessors if they are available.
> I can't believe it's relevant, but the Department's 'employees' relationship is mandatory, as is the inverse relationship.
No, it's not relevant -- such validation requirements are checked only when the Core Data store is about to be saved.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden