We currently have an object (User) which is used to store a student, teacher or parent.
User { firstName not null, lastName not null, gender, firstName2, lastName2 }
Student John is represented as ("John", "Williams", "M", null, null)
Teacher Patrick is represented as ("Patrick", "Gold", "M", null, null)
Parent Josh / Cindy of student John is represented as ("Josh", "Mason", "M", "Cindy", "Crawford")
We are unable to model a use case where a student doesn't have a father. How should we model this?
It seems to me you're not telling us everything. As far as I can tell from your data, your database can't count teachers or students. And the data about parents doesn't seem to record who they're the parents of .
My advice: untangle information about identity from information about roles and relationships. Use separate tables for each--one for identitiy, one for roles (if you must), and one for relationships.
Also, consider whether a teacher can also a parent, and whether a student can become a parent. (Both those are possible in the real world.)
You can do a table users with
Students, teachers and parents are all users. Parent_id refers creates a connection between a student and a parent. You can even create a foreign key to the same table from parent_id to id, but with NULL as default, so a student may exist without a father.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.