Suppose a Manager has a to-many relationship with Employee objects. Given a reference to a Manager object (i.e. NSManagedObject *manager), how do I get a reference to “the Employee with the lowest salary among all of those whose salaries exceed 10000″?
I can think of two possible approaches:
Approach 1: constructing an NSFetchRequest and specifying the Manager wanted with the object ID of the Manager in question.
Approach 2: some kind of key-value coding expression on Manager, e.g. [manager valueForKeyPath:@"..."] (with some use of NSPredicate?)
I’m inclined towards Approach 2 if there’s a plausible solution. Please enlighten me.
You can filter your array of
Employeerelationship to get the one you want.1) First, get all the
Employeewith salaries over 10000:2)Then sort it in descending order
3)Then just get your employee