Say we have a entity Company that has a to-many relationship to the Employee entity via the employees.
If I want to find the last created Employee (assume Employee has a NSDate property created), which of these two approaches is better?
- create a
NSFetchRequestonEmployee, restricted to"company == %@", someCompany, sort bycreated, and set thefetchLimitto 1 - or use
sortedArrayUsingDescriptors:onsomeCompany.employeeswith aNSSortDescriptoroncreatedand take the first?
While the second approach seems more straight forwards, I'm concerned about the actual processing. The first approach would allow the system to tailor a custom query, while the second does some in-memory sorting? I guess it boils down to whether to-many relationships are lazy or not.