开发者

Formatting NSPredicate: Matching "ANY" that match two conditions

开发者 https://www.devze.com 2023-03-28 11:51 出处:网络
**I\'m a bit at a loss about how to format an NSPredicate where \"any\" of a certain relationship matches more than one condition.

**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 empl开发者_Go百科oyee 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
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号