• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Programatically setting relationship [<-->>] results in two objects in table
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Prev by Date: Re: Where's "Multiple Fonts Allowed"?
  • Next by Date: Re: bindings + actions
  • Previous by thread: Re: Cocoa-dev Digest, Vol 3, Issue 675
  • Next by thread: determine if file is package
  • Index(es):
    • Date
    • Thread