One-to-many relationship
One-to-many relationship
- Subject: One-to-many relationship
- From: Norio Ota <email@hidden>
- Date: Thu, 27 Sep 2007 14:23:16 +0900
Hi guys,
I have just got how to set "many" relationship by using addObject:,
but don't know how to set "one" relationship.
I went see DepartmentAndEmploee sample, but I still don't understand.
Would you tell me which API is the one I should use? Or I don't need
to do anything for that?
Entity: Employ
name(attribute)
department(one relationship)
Entity: Department
dept_name(attribute)
employees(many relationship)
The following code is what I wrote for a Department object adding new
employee object.
NSMutableSet * aSet = [deptObject mutableSetValueForKey:@"employees"];
for (i = 0; i < maxnum; ++i )
{
id iEmployee = [NSEntityDescription
insertNewObjectForEntityForName:@"Employee"
inManagedObjectContext:context];
[aSet addObject:iEmployee];
}
But how should I connect the department object to 'department' of
Employ object.
Is the following code OK?
[iEmployee setValue:deptObject forKey:@"department"];
Thank you for reading this poor explanation.
Norio Ota
_______________________________________________
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