So this is something that we've been struggling to try and figure out how to optimize.
In a simple world, this might be solved by a simple many-to-many bridging table like this:
teachers_students_mappings
id | teacher_id | student_id |
---|---|---|
1 | 1 | 1 |
2 | 1 | 2 |
3 | 1 | 3 |
4 | 2 | 1 |
However, we have another complexity here to grapple with. A student record can come from different "sources", i.e.:
- The student was created by another system transferring the records of that student and their classes to us (most student and teacher-student relationship records are created this way).
- The student registered on their own (through an app), or
- The student was manually created by a teacher (via a teacher portal)
We therefore have cases where student records, from different sources, should be related to each other too:
students
id | name | id_number | source_type |
---|---|---|---|
1 | Rachel Doe | 9898123 | created_by_system |
2 | Rachel Doe | 9898123 | app_user |
3 | John Doe | 9833456 | created_by_teacher |
e.g. Above, we have a case where student_ids 1 & 2, Rachel Doe, are actually the same person. The first record was generated automatically by the system, and the 2nd record was created when Rachel registered in the system on her student app. Both records share an id_number
, which is a unique identifier in the school.
If we made it so both student_ids 1 and 2 were linked to all of Rachel's teachers, her teachers would be seeing duplicated records, i.e. both Rachel's app account, and her record created by the system. It seems it might therefore be smarter to relate both these student_id
records to each other, but how would that impact the teachers_students_mappings
table?
It is also theoretically possible that 3 unique student records exist for the same student (i.e. the teacher manually created a record, then the system created it, then the student created an account on the app).