diff --git a/Code/CoreData/RKConnectionDescription.h b/Code/CoreData/RKConnectionDescription.h index 52959e3a..d564ccfb 100644 --- a/Code/CoreData/RKConnectionDescription.h +++ b/Code/CoreData/RKConnectionDescription.h @@ -19,7 +19,6 @@ // #import -#import "RKDynamicMappingMatcher.h" /** The `RKConnectionDescription` class describes a means for connecting a Core Data relationship. Connections can be established either by foreign key, in which case one or more attribute values on the source entity correspond to matching values on the destination entity, or by key path, in which case a key path is evaluated on the object graph to obtain a value for the relationship. Connection objects are used by instances of `RKRelationshipConnectionOperation` to connect a relationship of a given managed object. @@ -153,13 +152,13 @@ @property (nonatomic, assign) BOOL includesSubentities; /** - An optional predicate for filtering objects to be connected. + An optional predicate for conditionally evaluating the connection based on the state of the source object. */ -@property (nonatomic, copy) NSPredicate *predicate; +@property (nonatomic, strong) NSPredicate *sourcePredicate; /** - An optional matcher that filters the source object to be connected. + An optional predicate for filtering objects to be connected. */ -@property (nonatomic, strong) RKDynamicMappingMatcher* matcher; +@property (nonatomic, copy) NSPredicate *destinationPredicate; @end diff --git a/Code/CoreData/RKConnectionDescription.m b/Code/CoreData/RKConnectionDescription.m index f05dcdfd..538f329c 100644 --- a/Code/CoreData/RKConnectionDescription.m +++ b/Code/CoreData/RKConnectionDescription.m @@ -80,7 +80,7 @@ static NSSet *RKSetWithInvalidAttributesForEntity(NSArray *attributes, NSEntityD if ([self class] == [RKConnectionDescription class]) { @throw [NSException exceptionWithName:NSInternalInconsistencyException reason:[NSString stringWithFormat:@"%@ Failed to call designated initializer. " - "Invoke initWithRelationship:sourceKeyPath:destinationKeyPath:matcher: instead.", + "Invoke initWithRelationship:attributes: instead.", NSStringFromClass([self class])] userInfo:nil]; } diff --git a/Code/CoreData/RKRelationshipConnectionOperation.m b/Code/CoreData/RKRelationshipConnectionOperation.m index e443c3f2..8c49bc71 100644 --- a/Code/CoreData/RKRelationshipConnectionOperation.m +++ b/Code/CoreData/RKRelationshipConnectionOperation.m @@ -139,16 +139,14 @@ static NSDictionary *RKConnectionAttributeValuesWithObject(RKConnectionDescripti - (id)findConnected { id connectionResult = nil; - - if (self.connection.matcher && ![self.connection.matcher matches:self.managedObject]) - return nil; + if (self.connection.sourcePredicate && ![self.connection.sourcePredicate evaluateWithObject:self.managedObject]) return nil; if ([self.connection isForeignKeyConnection]) { NSDictionary *attributeValues = RKConnectionAttributeValuesWithObject(self.connection, self.managedObject); NSSet *managedObjects = [self.managedObjectCache managedObjectsWithEntity:[self.connection.relationship destinationEntity] attributeValues:attributeValues inManagedObjectContext:self.managedObjectContext]; - if (self.connection.predicate) managedObjects = [managedObjects filteredSetUsingPredicate:self.connection.predicate]; + if (self.connection.destinationPredicate) managedObjects = [managedObjects filteredSetUsingPredicate:self.connection.destinationPredicate]; if (!self.connection.includesSubentities) managedObjects = [managedObjects filteredSetUsingPredicate:[NSPredicate predicateWithFormat:@"entity == %@", [self.connection.relationship destinationEntity]]]; if ([self.connection.relationship isToMany]) { connectionResult = managedObjects; diff --git a/Tests/Logic/CoreData/RKRelationshipConnectionOperationTest.m b/Tests/Logic/CoreData/RKRelationshipConnectionOperationTest.m index bfa0981c..b44a6b61 100644 --- a/Tests/Logic/CoreData/RKRelationshipConnectionOperationTest.m +++ b/Tests/Logic/CoreData/RKRelationshipConnectionOperationTest.m @@ -256,7 +256,7 @@ expect(secondChild.friends).to.equal(expectedFriends); } -- (void)testConnectionMatcher +- (void)testConnectionWithSourcePredicate { RKHuman *human = [RKTestFactory insertManagedObjectForEntityForName:@"Human" inManagedObjectContext:nil withProperties:nil]; human.sex = @"female"; @@ -271,16 +271,14 @@ [mapping addConnectionForRelationship:@"cats" connectedBy:@"sex"]; RKFetchRequestManagedObjectCache *managedObjectCache = [RKFetchRequestManagedObjectCache new]; RKConnectionDescription *connection = [mapping connectionForRelationship:@"cats"]; - - RKEntityMapping *catMapping = [RKEntityMapping mappingForEntityForName:@"Cat" inManagedObjectStore:[RKTestFactory managedObjectStore]]; - connection.matcher = [[RKDynamicMappingMatcher alloc] initWithKeyPath:@"sex" expectedValue:@"male" objectMapping:catMapping]; + connection.sourcePredicate = [NSPredicate predicateWithFormat:@"sex == %@", @"male"]; RKRelationshipConnectionOperation *operation = [[RKRelationshipConnectionOperation alloc] initWithManagedObject:human connection:connection managedObjectCache:managedObjectCache]; [operation start]; assertThat(human.cats, hasCountOf(0)); } -- (void)testConnectionPredicate +- (void)testConnectionWithDestinationPredicate { RKHuman *human = [RKTestFactory insertManagedObjectForEntityForName:@"Human" inManagedObjectContext:nil withProperties:nil]; human.sex = @"female"; @@ -294,7 +292,7 @@ [mapping addConnectionForRelationship:@"cats" connectedBy:@"sex"]; RKFetchRequestManagedObjectCache *managedObjectCache = [RKFetchRequestManagedObjectCache new]; RKConnectionDescription *connection = [mapping connectionForRelationship:@"cats"]; - connection.predicate = [NSPredicate predicateWithFormat:@"birthYear = 2011"]; + connection.destinationPredicate = [NSPredicate predicateWithFormat:@"birthYear = 2011"]; RKRelationshipConnectionOperation *operation = [[RKRelationshipConnectionOperation alloc] initWithManagedObject:human connection:connection managedObjectCache:managedObjectCache];