Retrieving Values ​​for One or More Relationships Using NSPredicate

I have a basic data model with a legal department and employees with many department-employee relationships (department ->> employee). I need to get all departments with employees connecting a date between two dates.

How do I set a predicate for this ???

Thank....

+3


source to share


1 answer


I think you need SUBQUERY here:

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

      



employees

is the many relationship from department to employee.

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

+3


source







All Articles