Rework deletion operations to avoid deleting objects that would be valid if mapping we allowed to assign them to the desintation relationship. refs #1225

This commit is contained in:
Blake Watters
2013-03-14 20:12:56 -04:00
parent 8ff6f62297
commit 96b9d6f683
4 changed files with 30 additions and 3 deletions

View File

@@ -323,9 +323,6 @@ extern NSString * const RKObjectMappingNestingAttributeKeyName;
return NO;
}
// Delete the object immediately if there are no connections that may make it valid
if ([connections count] == 0 && RKDeleteInvalidNewManagedObject(mappingOperation.destinationObject)) return YES;
/**
Attempt to establish the connections and delete the object if its invalid once we are done
@@ -339,6 +336,9 @@ extern NSString * const RKObjectMappingNestingAttributeKeyName;
}];
}];
// Add a dependency on the parent operation. If we are being mapped as part of a relationship, then the assignment of the mapped object to a parent may well fulfill the validation requirements. This ensures that the relationship mapping has completed before we evaluate the object for deletion.
if (self.parentOperation) [deletionOperation addDependency:self.parentOperation];
for (RKConnectionDescription *connection in connections) {
RKRelationshipConnectionOperation *operation = [[RKRelationshipConnectionOperation alloc] initWithManagedObject:mappingOperation.destinationObject connection:connection managedObjectCache:self.managedObjectCache];
[operation setConnectionBlock:^(RKRelationshipConnectionOperation *operation, id connectedValue) {