newbie problems with master-detail relationship
newbie problems with master-detail relationship
- Subject: newbie problems with master-detail relationship
- From: shaun bear <email@hidden>
- Date: Sun, 29 Oct 2006 22:58:59 +0100
I have created a test program with a master detail relationship. It
contains 2 Entities:
"Master" and "Detail". I have generated custom classes that sub-
class Managed Object
Class automatically for these entities, with accessors with Xcode.
I have then dragged the entities into interface builder,creating a
tableview bound to their
respective object arrays. I have bound "Detail Array
Controller"Content set to "Master Array Controller".
I have set the Object class name for each Array controller to their
respective classes.
This works fine if I want to add new rows using the interface.
Next I created an method: add in MyDocument, because I want to be
able to add new "Master" and "Detail"
records, programatically at runtime. When the method: add (below) is
invoked, the the new row shows up for the Master
table but not the Detail row. If invoke the method a second time, I
get the following error message:
[<NSCFString 0x2d04c> valueForUndefinedKey:]: this class is not key
value coding-compliant for the key child.
I have the following accessors for the key child in the Detail.h :
// Declaration
- (NSString *)child;
- (void)setChild:(NSString *)value;
Am I adding instantiating the detail object correctly?
Is somthing I should be doing in bindings that I am missing?
Can you see anything wrong with method: add?
Thanks in advance for your help?
- (IBAction)add:(id)sender {
NSManagedObjectContext *managedObjectContext = [self
managedObjectContext];
[[managedObjectContext undoManager] disableUndoRegistration];
master =[NSEntityDescription
insertNewObjectForEntityForName:@"Master"
inManagedObjectContext:managedObjectContext];
[master setParent:@"test"];
detail = [NSEntityDescription
insertNewObjectForEntityForName:@"Detail"
inManagedObjectContext:managedObjectContext];
[detail setChild:@"test"];
[master addDetailObject: @"detail"];
[managedObjectContext processPendingChanges];
[[managedObjectContext undoManager] enableUndoRegistration];
}
_______________________________________________
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