Core Data fetch returns wrong entities.
Core Data fetch returns wrong entities.
- Subject: Core Data fetch returns wrong entities.
- From: David Burnett <email@hidden>
- Date: Sun, 05 Mar 2006 13:10:15 +0000
I'm sure it's a problem with my understanding of low level core data
programming but I'm getting some odd results.
My entity layout is set up like this.
Genome ---1 to N---> XForms
When I run the following code
NSArray *genomes;
NSPredicate * predicate;
NSFetchRequest *fetch = [[NSFetchRequest alloc] init];
[fetch setEntity:
[NSEntityDescription
entityForName:@"Genome"
inManagedObjectContext:moc]];
genomes = [moc executeFetchRequest:fetch error:nil];
[fetch release];
The NSArray contains a mix of all the Genome and XForm entities
in the context.
This is also demonstrated when a NSTableView with columns bound
to Genome attributes which gets rows for each Genome and
XForm.
The code I've used to build up the context goes along these lines
(this code is simplified for brevity).
genomeEntity = [NSEntityDescription
insertNewObjectForEntityForName:@"Genome"
inManagedObjectContext:moc];
...
xFormSet = [[NSMutableSet alloc] initWithCapacity:numberOfXForms];
for(i=0; i<numberOfXForms;i++) {
xFormEntity = [NSEntityDescription
insertNewObjectForEntityForName:@"XForm"
inManagedObjectContext:moc];
[xFormSet addObject:xFormEntity];
...
}
[genomeEntity setValue:xFormSet forKey:@"xforms"];
I'm guessing its has something to do with a conflict between
insertNewObjectForEntityForName:inManagedObjectContext
and using setValue:forKey to add a set of child entities, however...
a) I can find no examples or description of how to create and configure
a managed object without adding it to the context.I would have thought
there would be a mention is the doc's in the Manipulating Relationships
chapter of the Relationships article of the Core Data Programming
Guide if it was not the proper code to use.
b) I'm a little concerned that I'm trying to fetch one entity type
but getting a mix of entity types back
So does anyone have any idea's of exactly what I'm getting wrong ?
I've put a copy of the project (it's GPL'd code) at
http://oxidizer.sf.net/oxidizer_core.zip
if anyone is interested, it's a 3MB download.
Dave
_______________________________________________
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