Skip navigation.
 
mlRetrieving Master from Slave
FROM : Mike Rossetti
DATE : Tue Jan 29 06:17:25 2008

The following refers to a Core Data document-based application with a 
'Master' entity that has a many-to-one relationship to a 'Slave' 
entity.  The Master is the root entity of the document.  I', building 
to 10.5 and my implementation is nearly identical to the one 
demonstrated in the "NSPersistentDocument Core Data Tutorial".

At the point of my question, the document object has been retrieved 
from disk and I am editing by adding a new Slave to the existing 
Master entity.  In Slave's awakeFromInsert I would like to retrieve 
the Master and initialize some attributes in the new Slave entity 
using attributes from the Master.

I'm a little confused as to how retrieve a reference to the Master.  I 
originally thought that I could just use self.master or [self 
valueForKey:@"master"] but the 'master' member is nil.  Re-reading the 
"Adopting the Mediator Pattern" in the "NSPersistentDocument Core Data 
Tutorial" made me try fetching the Master using an 
executeFetchRequest, which works.  The tutorial suggests that simply 
retrieving the master from the relevant object controller is even more 
appropriate but makes me wonder how the slave is supposed to get a 
reference to the master entity object controller.

This seems like a lot of work and I can't help but think that there is 
a simpler way to retrieve the 'master' object.

Any suggestions?  Examples?

Thanks,
Mike

Related mailsAuthorDate
No related mails found.