William Falcon
William Falcon

Reputation: 9813

nspredicate for searching entity relationships

I wrote the following predicate for the following structure, not sure if its working correctly:

I have a Car.h managedobject

Car.h - name, make, model.

toCarParts relationship - CarPart.h - wheel, tire, mirror, etc...

i have an array with many Car.h objects I want to find only those that have a tire (so i have to look through toCarParts at all objects, and if any of the CarParts match my query, I need to pull that car into a results array)

will this predicate do this?

 NSPredicate *predicate = [NSPredicate predicateWithFormat:@"ANY toCarParts.name == [c] %@", carPartString];

Thank you in advance

Upvotes: 1

Views: 309

Answers (1)

Bejmax
Bejmax

Reputation: 945

I believe this should work for you.

NSPredicate *predicate = 
   [NSPredicate predicateWithFormat:@"ANY toCarParts.name like %@", carPartString];

Upvotes: 1

Related Questions