I have two core data entities named Assignment and Question. Assignment entity has assignment details like its name, id etc. Question table has question name, id etc. Assignment has one to many relationship with Question. When I try to fetch the assignments details from server, I get assignment and question data and both Assignment and Question entities are updated in the core data store. Note that two different assignments might share same questions.
Now lets consider, assignment 1 has questions with id 1,2 and 3. Where as assignment 2 has questions with id 4, 5 and 1. In my question table it has only 5 entries as the question with id 1 is common in both the assignments.
I am using a NSFetchedResultsController to poulate this on the UI. I have an issue with fetching the questions in the same order it is added to the core data store(database)
For example: For assignment 2, I need questions in oder 4,5 and 1. There is no unique key using which I can create the sort descriptor.Without sort descriptor I can not create NSFetchRequest and without that it is not possible to create NSFetchedResultsController. Any thoughts on solving this issue?
To my mind, the best pattern would be to create a new entity,
AssignmentQuestion, that has a has many-to-one relationship toAssignmentand a many-to-one relationship toQuestion, as well as a sequence number attribute.