Egil
Egil

Reputation: 31

Select item based on property of related item

I have one table, 'Person' and another, Car, where the relation is one-to-many (one person may have many cars).

How can a write a predicate to get all persons who have a car (any one if they have more) with a certain property?

Upvotes: 0

Views: 36

Answers (1)

LK.
LK.

Reputation: 4569

Something like this?

NSEntityDescription *entityDesc = [NSEntityDescription entityForName:@"Person" inManagedObjectContext:context];
NSString            *str        = @"ANY cars.property == 'value'";
NSPredicate         *predicate  = [NSPredicate predicateWithFormat:str];
...

Upvotes: 1

Related Questions