On 2010 Jul 08, at 19:28, Noah Desch wrote:

> On Jul 8, 2010, at 7:33 PM, [email protected] wrote:
> 
>> 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.  As always, you must be careful you don't screw up Undo.  For 
discussion of this, see list archives during the last couple weeks, thread:

   Re: CoreData and undo/redo : how to add a managed object with attributes 
already set in the undo/redo stack ?

Several solutions are given.  Gumboots asked which is "best".  I don't know.  
They all work.

An interesting question is how this happens in the DepartmentAndEmployees 
sample code.  When I create a document with an employee, save the file and dump 
it with sqlite3, it appears that the Employee is related to the Department.  
But I looked at that code for a few minutes yesterday and can't see how it 
happened.  The only time that an Employee is set to a Department or vice versa 
is in the -paste method, but that doesn't run.  Does anyone know?

_______________________________________________

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