Assume I use MySQL, and there are two tables, students
and parents_guardians
table. Table students
is used to store students' data. The parents_guardians
table is used to store students' parents and students' guardians.
So either a student can have a father and a mother as his parents, or a student can have an uncle and an aunt as his guardians. To do that, I add one more table as pivot table, which is students_parents_guardians
table.
This pivot table contains 3 columns:
students_id
parents_id
guardians_id
The question is: Is this good design? And how can I do that in Laravel?
So far, I'm unable to do that. What I can do is create 5 table:
students
table to store student's dataparents
table to store parents' datastudents_parents
as pivot table to perform relationship between students and parents.guardians
table to store guardian's datastudents_guardians
as pivot table to perform relationship bwtween students and guardians.
I believe this is a bad idea, and I should normalize all of it.
parent
andguardian
tables? A parent is automatically a guardian. Have aguardian
table with anis_parent
Boolean field! 5 tables -> 3!WHERE is_parent = [TRUE | FALSE]
)! Plus, it will greatly simplify queries for both, and, as has been pointed out, the distinction between parent and guardian for a school is probably minimal!guardian
table with anis_parent
BOOLEAN field Very important - what version of MySQL are you using?