Skip to content

Commit

Permalink
Store new objects by lookupValue instead of primaryKeyValue. This avo…
Browse files Browse the repository at this point in the history
…ids creation of duplicated objects the are manufactured by findOrCreateInstanceOfEntity:
  • Loading branch information
blakewatters committed Jul 8, 2011
1 parent e31061b commit 40eb842
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Code/CoreData/RKManagedObjectStore.m
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ - (NSManagedObject*)findOrCreateInstanceOfEntity:(NSEntityDescription*)entity wi

if (object == nil) {
object = [[[NSManagedObject alloc] initWithEntity:entity insertIntoManagedObjectContext:self.managedObjectContext] autorelease];
[dictionary setObject:object forKey:primaryKeyValue];
[dictionary setObject:object forKey:lookupValue];
}

return object;
Expand Down
10 changes: 5 additions & 5 deletions RestKit.xcodeproj/xcshareddata/xcschemes/UISpec.xcscheme
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
<EnvironmentVariables>
<EnvironmentVariable
key = "UISPEC_SPEC"
value = "RKManagedObjectLoaderSpec"
value = "RKObjectMappingNextGenSpec"
isEnabled = "NO">
</EnvironmentVariable>
<EnvironmentVariable
Expand All @@ -72,7 +72,7 @@
</EnvironmentVariable>
<EnvironmentVariable
key = "UISPEC_EXAMPLE"
value = "itShouldDeleteObjectFromLocalStoreOnDELETE"
value = "itShouldRegisterRailsIdiomaticObjects"
isEnabled = "NO">
</EnvironmentVariable>
<EnvironmentVariable
Expand All @@ -87,12 +87,12 @@
</EnvironmentVariable>
<EnvironmentVariable
key = "UISPEC_SPEC"
value = "RKObjectMappingNextGenSpec"
isEnabled = "NO">
value = "RKManagedObjectStoreSpec"
isEnabled = "YES">
</EnvironmentVariable>
<EnvironmentVariable
key = "UISPEC_EXAMPLE"
value = "itShouldSetTheErrorWhenMappingOperationFails"
value = "itShouldAllowYouToPOSTAnObjectAndMapBackNonNestedContent"
isEnabled = "NO">
</EnvironmentVariable>
<EnvironmentVariable
Expand Down
7 changes: 7 additions & 0 deletions Specs/CoreData/RKManagedObjectStoreSpec.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,11 @@ - (void)itShouldCoercePrimaryKeysToStringsForLookup {
assertThat(newReference, is(equalTo(human)));
}

- (void)itShouldStoreNewInstancesOfCreatedObjectsByStringKey {
RKManagedObjectStore* objectStore = RKSpecNewManagedObjectStore();
NSManagedObject* firstInstance = [objectStore findOrCreateInstanceOfEntity:[RKHuman entity] withPrimaryKeyAttribute:@"railsID" andValue:[NSNumber numberWithInt:1234]];
NSManagedObject* secondInstance = [objectStore findOrCreateInstanceOfEntity:[RKHuman entity] withPrimaryKeyAttribute:@"railsID" andValue:[NSNumber numberWithInt:1234]];
assertThat(secondInstance, is(equalTo(firstInstance)));
}

@end

0 comments on commit 40eb842

Please sign in to comment.