Sorting order in Core Data with multi-multi-dependency

Let's say I'm modeling a school, so I have 2 objects: a student and a class. For some reason, I want each class list to have its own sort order. In a simple connection, this would mean that the student had a sortOrder attribute and just sorted the list by that number. The problem is that a student can be of the order of 3 in one class and of the order of 6 in another. How do I store these orderings in Core Data so that I can easily access them and sort the lists correctly?

 Student                  Class
 classes  <<--------->>  students
    ^                       ^
    |                       |
unordered                ordered

This chart may help explain what I'm trying to do. Students "registry", which I would like to receive in a certain order, are stored somewhere, which can be any order. Keeping this order is something that I'm not sure how to make it the most efficient. Creating a bunch of Order objects and trying to manage links sounds like a lot of overhead, and it seems like there should be a better way.

+3
source share
2 answers

Student ↔> StudentClass ↔> Class

StudentClass
----
studentID
order
classID 

Then you can choose as needed.

For example, you have student. Extract all StudentClass where StudentID is student.studentID. Then you have order, as well as access to the class.

, -, . , , MOGenerator: https://github.com/rentzsch/mogenerator

EDIT: , . .

0

NSSortDescriptors, Class, . , ( ) NSFetchedResultsController, .

NSSortDescriptor, index ( ) Student, Order Student. . , Core Data . .

+1

Source: https://habr.com/ru/post/1781540/


All Articles