Literally from Developer Library:
Recall that you can follow relationships in a predicate using a key path. The following example illustrates the creation of a predicate to find employees that belong to a department with a given name (but see also Performance).
If you use a to-many relationship, the construction of a predicate is slightly different. If you want to fetch Departments in which at least one of the employees has the first name "Matthew," for instance, you use an ANY operator as shown in the following example:
_________________________________________
Now, I dont understand how Core Data is able to know we are searching for employees in
and we are searching for departments in
Recall that you can follow relationships in a predicate using a key path. The following example illustrates the creation of a predicate to find employees that belong to a department with a given name (but see also Performance).
Code:
NSString *departmentName = ... ;
NSPredicate *predicate = [NSPredicate predicateWithFormat:
@"department.name like %@", departmentName];
Code:
NSPredicate *predicate = [NSPredicate predicateWithFormat:
@"ANY employees.firstName like 'Matthew'"];
_________________________________________
Now, I dont understand how Core Data is able to know we are searching for employees in
Code:
NSPredicate *predicate = [NSPredicate predicateWithFormat:
@"department.name like %@", departmentName];
Code:
Predicate *predicate = [NSPredicate predicateWithFormat:
@"ANY employees.firstName like 'Matthew'"];
Last edited by a moderator: