Database design: Is there a much better way on this current relationships?
-
21-12-2020 - |
Question
I have a faculty
and student
table to store each information, respectively. I made a contact
table to store the contacts of either faculty or student. I would like to use the contact
table as a generic one, means it can be used by either faculty
or student
.
My table diagram is something like this.
I compressed faculty and student into a USER table
and have an account type
in that table to know whether it is a faculty
or student
type of user. Then the USER
table will have a one is to many relationship with the contact table.
Student
Faculty
Contacts
Student & Faculty = User table
User table -----<- Contact table
Solution
True story: I was a student at my school, then I taught there. Then one of the teachers took my class. You need to account for silliness like this.
And a faculty member or student isn't necessarily a user either.
Use table inheritance.
Faculty : Individual : Party
Student : Individual : Party
Where :
means inherits.
Party hasOne User
A contact
is a relationship between two parties:
Party hasMany ContactRelationships belongsTo Party
See Ready-to-Use Database models example for reference models.