mirror of
https://github.com/zhigang1992/RestKit.git
synced 2026-01-12 22:51:50 +08:00
Add support for skipping relationship connections if all connection attributes evaluate to nil. Add support for establishing connections when some connection attributes evaluate to nil. fixes #1099 closes #1102
This commit is contained in:
@@ -45,9 +45,9 @@ static NSDictionary *RKConnectionAttributeValuesWithObject(RKConnectionDescripti
|
||||
for (NSString *sourceAttribute in connection.attributes) {
|
||||
NSString *destinationAttribute = [connection.attributes objectForKey:sourceAttribute];
|
||||
id sourceValue = [managedObject valueForKey:sourceAttribute];
|
||||
[destinationEntityAttributeValues setValue:sourceValue forKey:destinationAttribute];
|
||||
[destinationEntityAttributeValues setValue:sourceValue ?: [NSNull null] forKey:destinationAttribute];
|
||||
}
|
||||
return destinationEntityAttributeValues;
|
||||
return [[destinationEntityAttributeValues allValues] isEqualToArray:@[ [NSNull null] ]] ? nil : destinationEntityAttributeValues;
|
||||
}
|
||||
|
||||
@interface RKRelationshipConnectionOperation ()
|
||||
@@ -143,6 +143,7 @@ static NSDictionary *RKConnectionAttributeValuesWithObject(RKConnectionDescripti
|
||||
|
||||
if ([self.connection isForeignKeyConnection]) {
|
||||
NSDictionary *attributeValues = RKConnectionAttributeValuesWithObject(self.connection, self.managedObject);
|
||||
if ([attributeValues count] == 0) return nil;
|
||||
NSSet *managedObjects = [self.managedObjectCache managedObjectsWithEntity:[self.connection.relationship destinationEntity]
|
||||
attributeValues:attributeValues
|
||||
inManagedObjectContext:self.managedObjectContext];
|
||||
|
||||
Reference in New Issue
Block a user