Fix issue with incorrect quoting within the mapping cache causing duplicated objects. closes #598. refs #578

This commit is contained in:
Blake Watters
2012-03-20 21:11:29 -04:00
parent 175a90cabe
commit 368f5bf11a
4 changed files with 68 additions and 6 deletions

View File

@@ -26,14 +26,10 @@
NSAssert(primaryKeyValue, @"Cannot find existing managed object by primary key without a value");
NSAssert(managedObjectContext, @"Cannot find existing managed object with a context");
// NOTE: We coerce the primary key into a string (if possible) for convenience. Generally
// primary keys are expressed either as a number or a string, so this lets us support either case interchangeably
id lookupValue = [primaryKeyValue respondsToSelector:@selector(stringValue)] ? [primaryKeyValue stringValue] : primaryKeyValue;
NSFetchRequest* fetchRequest = [[NSFetchRequest alloc] init];
[fetchRequest setEntity:entity];
[fetchRequest setFetchLimit:1];
[fetchRequest setPredicate:[NSPredicate predicateWithFormat:@"%@ = %@", mapping.primaryKeyAttribute, lookupValue]];
[fetchRequest setPredicate:[NSPredicate predicateWithFormat:@"%K = %@", mapping.primaryKeyAttribute, primaryKeyValue]];
NSArray *objects = [NSManagedObject executeFetchRequest:fetchRequest];
RKLogDebug(@"Found objects '%@' using fetchRequest '%@'", objects, fetchRequest);