On Fri, 9 Jul 2010 05:12:10 -0700, Jerry Krinock said:

>>> Using the standard Employee/Department example, Whats the best way to
>set a default department for an Employee?
>>> So that every employee is created with a relationship to the
>"mailRoom" department.
>>
>> Probably to add some custom code to AwakeFromInsert in your employee
>NSManagedObjectSubclass to set its own department.
>
>Yes, that works.

Agreed, but it can be tricky.  How, from Employee's awakeFromInsert, do
you get the default Department?  One way would be to fetch.  I do this
and it's generally fine, except for a bug in NSArrayController:

6723165 fetching in awakeFromInsert causes 2 notifications to
NSArrayController

Looks like this is actually mentioned in awakeFromInsert's docs now.  Nice!

So if you have a tableview (bound to an array controller) of Employees,
adding a new Employee will result in two items in the table (but not
your model).

--
____________________________________________________________
Sean McBride, B. Eng                 [email protected]
Rogue Research                        www.rogue-research.com
Mac Software Developer              Montréal, Québec, Canada


_______________________________________________

Cocoa-dev mailing list ([email protected])

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to