Core Data: How do I populate detail entities (tables) programmatically?
Core Data: How do I populate detail entities (tables) programmatically?
- Subject: Core Data: How do I populate detail entities (tables) programmatically?
- From: "Frederick C. Lee" <email@hidden>
- Date: Sun, 11 Dec 2005 10:53:22 -0800
Greetings:
I know how to populate the master table (e.g., the Country entity).
But how do I populate a dependent table (e.g., the City entity)?
Scenario:
Controller is an instantiated NSPersistentDocument.
Model:
Country:City --> 1:many.
I'm using the following to create an entity master object (Country)
and populate it:
- (void)addNewEntry {
[[managedObjectContext undoManager] disableUndoRegistration];
[self setCountry:[NSEntityDescription
insertNewObjectForEntityForName:@"Country"
inManagedObjectContext:managedObjectContext]];
[[self country] setValue:@"Switzerland" forKey:@"name"];
[[self country] setValue:@"Franc" forKey:@"currency"];
[[self country] setValue:@"
http://info.ch" forKey:@"url"];
[managedObjectContext processPendingChanges];
[[managedObjectContext undoManager] enableUndoRegistration];
return;
}
The outcome via debugger is shown:
(gdb) po [self country]
<NSManagedObject: 0x50252c0> (entity: Country; id: 0x5023b10 <x-
core
data:///Country/t0AB19F3D-207C-4F6A-854C-7C8EAF9B272A> ; data: {
city = ();
coordinates = nil;
currency = Franc;
flag = nil;
map = ();
memo = nil;
name = Switzerland;
telephoneCode = nil;
time = nil;
url = "
http://info.ch";
})
---------
I have a few dependent entities (tables) that are '1:many' from the
master. 'city' and 'map' are both relationship links. I can use
the setValue: forKey: to populate current entity's attributes.
But I don't know how to follow into the associated dependent entities.
1) Do I access the assorted dependent entities through the master
entity or access each entity individually?
1a) But if I access each entity individually, how to I link 'em
together as a logical data group?
2) Do I do someting like 'city.name' via valueForKeyPath?
3) Do I need to create an assessor method per detailed/dependent
entity's attribute?
Regards,
Ric.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden