cocoa - Setting up relationships while importing core data? -
I have a memory-managed object context that is called import make, which I use to import records (e.g. Staff). I've parsed a file and established an employee object in import items with an important exception. Users confirm that they want to take action on% d employees but I did not know how and when to set up the "parent" relationship of employees (such as establishing their department).
For my purposes they are all imported into a single department (the user has already been selected inherently).
Obviously I can not establish relationships in two contexts, so I:
- Create a department in the import mock and then when I merge the changes, Real "department is merged with the" Import "section?
- 2) Join the employees and then all the newly imported employees (somehow !!!) and then determine their department?
- 3) Whatever other solution I have overlooked
It seems like a simple problem, but for some reason (sluggishness, exhaustion? Stupidity?) I understand Can not know how to go about it!
Thank you in advance!
If the department
objects have already been stored in a constant store, You can bring them into another managed object reference. Since your objects have to be constantly in the store (as the cross-store relationship is not allowed), you should be able to bring only those people you need importMoc
.
For example:
foreach (NSDictionary * record in employee records) {NSManagedObject * employee = [NSEntityDescription insertNewObjectForEntityForName: @ "EmployeeManagedObjectContext: importMoc]; // employee , But you do so that the NSString * managerID = [record objectForreak: @ "Something like this identifies the identifier"]; NSFetchRequest * managerFetchRequest = [[NSFetchRequest alloc] init]; [ManagerFetchRequest Setty: [NSEntity entityForName: @ " Manager "in managed object contact: import mok]]; [ManagerFetchRequest Net proof: [NSPredicate predicateWithFormat: @ "managerProperty ==% @", Manager ID]]; NSArray * Managers = [Import ExecutionFeatureQuest: managerFetchRequest Error: Zero]; // Do not be stupid like me; Hold error ;-) [ManagerFetchRequest release]; if ([managers count]! = 1) {// you probably have problems if this happens} [employee set valley: [manager object atindexx 0] for KA: @ "manager"]; }
You can also request a single request to bring all the managers in the importMoc
and then to find the correct position each time that array You can filter. Perhaps it would be much more efficient in other words, do not do what I told you to do above: -)
Comments
Post a Comment