CoreData: Sort and Section on Relationships
Posted
by David.Chu.ca
on Stack Overflow
See other posts from Stack Overflow
or by David.Chu.ca
Published on 2010-03-18T04:45:10Z
Indexed on
2010/03/18
4:51 UTC
Read the original article
Hit count: 242
I have two questions about using Core Data. Taking the typical case of Employee and Department as an example. The Employee entity has a relationship field "deparment" as to-one to Department, and the Department entity has a relationship "employee" as to-many to Employee entity.
I would like to display all the employees in a TableView in sections of department's names. I think that the NSFetchedResultsController should use Employee as entity. I am not sure how to use Department's name as a sort criteria, since it is in an employee's relationship field department's name. Can you use "DepartmentName" as a sort and add this to Employee entity class as a method which will return department's name for a given employee?
The second question is the section name. I would like to use department names as sections. Can I use the above method as sectionKeyPath's value for the NSFethedResultsController?
Not sure if I am on the right track.
© Stack Overflow or respective owner