Fix RKReplaceAssignmentPolicy. The problem was that new values for the relationship were gathered before the old values were deleted. Therefore if one of the new values was the same as the old value, the valueForRelationship collection would contain a deleted managed - not good.

Also fixed:
* The if statement near line 674 was incorrectly negated
 * Setting the relationship value around line 676 was redundant since it was done in the mapCoreDataToManyRelationshipValue:withMapping method.
This commit is contained in:
Charlie Savage
2013-03-06 01:24:23 -07:00
committed by Blake Watters
parent a9ef1fe39d
commit 535255a686

View File

@@ -647,7 +647,12 @@ static NSString * const RKMetadataKeyPathPrefix = @"@metadata.";
NSArray *existingObjectsArray = RKTransformedValueWithClass(existingObjects, [NSArray class], nil);
[relationshipCollection addObjectsFromArray:existingObjectsArray];
}
else if (relationshipMapping.assignmentPolicy == RKReplaceAssignmentPolicy) {
if (! [self applyReplaceAssignmentPolicyForRelationshipMapping:relationshipMapping]) {
return NO;
}
}
[value enumerateObjectsUsingBlock:^(id nestedObject, NSUInteger collectionIndex, BOOL *stop) {
id mappableObject = [self destinationObjectForMappingRepresentation:nestedObject withMapping:relationshipMapping.mapping inRelationship:relationshipMapping];
if (mappableObject) {
@@ -668,9 +673,6 @@ static NSString * const RKMetadataKeyPathPrefix = @"@metadata.";
// If the relationship has changed, set it
if ([self shouldSetValue:&valueForRelationship atKeyPath:relationshipMapping.destinationKeyPath]) {
if (! [self applyReplaceAssignmentPolicyForRelationshipMapping:relationshipMapping]) {
return NO;
}
if (! [self mapCoreDataToManyRelationshipValue:valueForRelationship withMapping:relationshipMapping]) {
RKLogTrace(@"Mapped relationship object from keyPath '%@' to '%@'. Value: %@", relationshipMapping.sourceKeyPath, relationshipMapping.destinationKeyPath, valueForRelationship);
[self.destinationObject setValue:valueForRelationship forKeyPath:relationshipMapping.destinationKeyPath];