Programatically setting relationship [<-->>] results in two objects in table
Programatically setting relationship [<-->>] results in two objects in table
- Subject: Programatically setting relationship [<-->>] results in two objects in table
- From: Karel Zelisse <email@hidden>
- Date: Sun, 21 May 2006 16:03:30 +0200
Father <-->> Child
I have a Core Data application which uses awakeFromInsert to
initialise a newly created Child object. This should automatically
set the relationship from the Child to the Father. There is only one
Father object.
Code below is from Child.
- (void) awakeFromInsert
{
[super awakeFromInsert];
[self setName: @"James"];
NSManagedObjectContext *managedObjectContext = [self
managedObjectContext];
fetchError = nil;
fetchRequest = [[NSFetchRequest alloc] init];
@try
{
entityDescription = [NSEntityDescription entityForName: @"Father"
inManagedObjectContext: managedObjectContext];
[fetchRequest setEntity: entityDescription];
fetchResults = [managedObjectContext executeFetchRequest:
fetchRequest error: &fetchError];
}
@finally
{
[fetchRequest release];
}
if( [fetchResults count] > 0 )
{
Father * myFather = [fetchResults objectAtIndex: 0];
[self setFather: myFather];
}
}
The Child Table will always show two identical new items with the
name James. Quitting and restarting the application removes one of
the duplicate objects.
How can I set the relationship programmatically without getting the
duplicate entry?
Thanks for your help.
Karel
_______________________________________________
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