Add optional support for connecting to subentities. fixes #1059

This commit is contained in:
Blake Watters
2012-12-19 18:32:03 -05:00
parent 5258328a39
commit 0a28ecb507
8 changed files with 62 additions and 0 deletions

View File

@@ -144,6 +144,13 @@
/// @name Setting the Predicate
///----------------------------
/**
Returns a Boolean value that determines if the connection includes subentities. If `NO`, then the connection will only be established to objects of exactly the entity specified by the relationship's entity. If `YES`, then the connection will be established to all objects of the relationship's entity and all subentities.
**Default**: `YES`
*/
@property (nonatomic, assign) BOOL includesSubentities;
/**
An optional predicate for filtering objects to be connected.
*/

View File

@@ -58,6 +58,7 @@ static NSSet *RKSetWithInvalidAttributesForEntity(NSArray *attributes, NSEntityD
if (self) {
self.relationship = relationship;
self.attributes = attributes;
self.includesSubentities = YES;
}
return self;
}

View File

@@ -145,6 +145,7 @@ static NSDictionary *RKConnectionAttributeValuesWithObject(RKConnectionDescripti
attributeValues:attributeValues
inManagedObjectContext:self.managedObjectContext];
if (self.connection.predicate) managedObjects = [managedObjects filteredSetUsingPredicate:self.connection.predicate];
if (!self.connection.includesSubentities) managedObjects = [managedObjects filteredSetUsingPredicate:[NSPredicate predicateWithFormat:@"entity == %@", [self.connection.relationship destinationEntity]]];
if ([self.connection.relationship isToMany]) {
connectionResult = managedObjects;
} else {