**I'm a bit at a loss about how to format an NSPredicate where "any" of a certain relationship matches more than one condition.
So for example, say I'm doing a fetch request for an "Employer" entity and I want to get all employers that have at least one employee under age 18. So, I can use "ANY employees.age < 18"
- simple enough. But say I want to match any that have an employee under 18 who also has the last name "Howser." That is, it's not enough for the employer to match both "any employee under 18" and "any employee named 'Howser'" - they have to have at least one employee that matches both conditions.
How would this predicate be formatted?
This is one of the rare circumstances where you need SUBQUERY
:
SUBQUERY(employees, $e, $e.age < 18 && $e.lastName == 'Howser').@count > 0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With