NSPredicate to filter NSS master data relationship by attribute

I have a relationship many-to-many

with two objects. One of them is Person

, the other is Clubs

. I want to write predicate

which will find all Person

entities that are in a specific one Club

. I also want to check the person attribute position

.

Here's what doesn't work:

NSFetchRequest *request = [[NSFetchRequest alloc] init];
[request setEntity:[NSEntityDescription entityForName:@"Person" inManagedObjectContext:self.managedObjectContext]];
[request setPredicate:[NSPredicate predicateWithFormat:@"position CONTAINS[cd] %@ AND IN %@", @"manager", self.clubs.people]];
NSArray *results = [self.managedObjectContext executeFetchRequest:request error:nil];

      

Fail on error:

Application terminated due to uncaught exception "NSInvalidArgumentException", reason: "Unable to parse format string" title CONTAINS [cd]% @AND IN% @ "'

I know I am doing something wrong here, any help?

+3


source to share


1 answer


As @pbasdf pointed out above, you must use self. However, the query will be much more efficient with the self condition, namely.



[NSPredicate predicateWithFormat:@"SELF IN %@ AND position CONTAINS[cd] %@", self.clubs.people, @"manager"];

      

+2


source







All Articles