removing NSManagedObject: a conceptual bug in my app
removing NSManagedObject: a conceptual bug in my app
- Subject: removing NSManagedObject: a conceptual bug in my app
- From: Davide Benini <email@hidden>
- Date: Thu, 22 Sep 2005 02:44:23 +0200
I am using core data to buil a bibliographic database.
Each "Entry" entity is associated to one or more "Author" entity.
I am building a routine that puts my filemaker database database into
this new app. The filemaker output I generate is XML.
This method tries to avoid duplicated authors (authors were not
mapped independently in the xml source, so the only way to identify
duplicates is checking their names and surname).
-(NSManagedObject *)distinctAuthor:(NSManagedObject *)givenAuthor
{
NSString *name= [NSString stringWithString:[authorObject
valueForKey:@"name"]];
NSString *surname= [NSString stringWithString:[authorObject
valueForKey:@"surname"]];
NSEntityDescription *authorEntity = [NSEntityDescription
entityForName:@"Author"
inManagedObjectContext:currentMoc];
NSFetchRequest *authorRequest = [[[NSFetchRequest alloc] init]
autorelease];
[authorRequest setEntity:authorEntity];
[authorRequest setPredicate:
[NSPredicate predicateWithFormat:@"name = %@ && surname =%
@", name, surname]];
NSArray *authors = [currentMoc executeFetchRequest:authorRequest
error:(nil)];
if ([authors count]>1) {
NSLog(@"autore duplicato %@", [[authors objectAtIndex:0]
valueForKey:@"surname"]);
NSManagedObject *duplicateAuthor = [authors objectAtIndex:1];
[currentMoc deleteObject:duplicateAuthor];
return [authors objectAtIndex:0];
}
else return givenAuthor;
}
Now, this SEEMS to work, but some of the authors with more than one
books gets associated only to one book.
I am sure there is a conceptual problem in the way I use the NSArray
from the fetch request; I guess sometimes I eliminate the "wrong"
instance of the author, and so the first "Entry" lose the "Author"
record it is associated to...
I hope this is clear.
Any suggestion to debug this code?
Davide
_______________________________________________
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