mirror of
https://github.com/zhigang1992/RestKit.git
synced 2026-04-23 12:27:52 +08:00
Add optional support for connecting to subentities. fixes #1059
This commit is contained in:
@@ -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.
|
||||
*/
|
||||
|
||||
@@ -58,6 +58,7 @@ static NSSet *RKSetWithInvalidAttributesForEntity(NSArray *attributes, NSEntityD
|
||||
if (self) {
|
||||
self.relationship = relationship;
|
||||
self.attributes = attributes;
|
||||
self.includesSubentities = YES;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user