Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fetching one to many relation values using NSPredicate

I have core data model with entities department and employees with to-many relationship from department to employee (department-->> employee).I need to fetch all the departments with employees joining date between two dates.

How to Set the predicate for this ???

Thank You....

like image 259
Yatheesha Avatar asked Feb 11 '26 21:02

Yatheesha


1 Answers

I think you need a SUBQUERY here:

[NSPredicate predicateWithFormat:@"SUBQUERY(employees, $e, $e.joinDate >= %@ AND $e.jointDate >= %@).@count > 0",
     fromDate, toDate]

employees is the to-many relationship from Department to Employee.

(See expressionForSubquery:usingIteratorVariable:predicate: in the "NSExpression Class Reference", where a similar problem and the SUBQUERY solution is documented).

like image 71
Martin R Avatar answered Feb 13 '26 15:02

Martin R



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!