nick
nick

Reputation: 57

NSPredicate for one-to-many relationship

I need to fetch all Departments that don't have an Employee called "Bob"

Based on other answers on SO that I've read, I've tried this:

name = @"Bob";
predicate = [NSPredicate predicateWithFormat:@"ALL employees.name != %@", name];

but it doesn't seem to work. Any ideas?

Thanks.

Upvotes: 2

Views: 2707

Answers (1)

Martin R
Martin R

Reputation: 540065

Do do not need a subquery here:

name = @"Bob";
predicate = [NSPredicate predicateWithFormat:@"NOT ANY employees.name == %@", name];

For some reason, the "ALL" aggregate does not work with to-many relationships, but the "ANY" aggregate works.

Upvotes: 7

Related Questions