-
-
Save lanbau/7e67338b54a0b3bed792 to your computer and use it in GitHub Desktop.
Many-to-many example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# For http://stackoverflow.com/a/7296873/396458 | |
student: student_id, first_name, last_name | |
classes: class_id, name, teacher_id | |
student_classes: class_id, student_id # the junction table | |
students: | |
id | first | last | |
===================== | |
1 | John | Lee | |
2 | Jane | Wilson | |
3 | Daniel | Gomez | |
classes: | |
id | name | teacher_id | |
========================== | |
1 | Biology | 2 | |
2 | Physics | 4 | |
3 | English | 77 | |
student_classes | |
s_id | c_id | |
====================== | |
1 | 2 # John is taking Physics | |
1 | 3 # John is taking English | |
2 | 2 # Jane is taking Physics | |
3 | 1 # Daniel is taking Biology | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://stackoverflow.com/questions/7296846/how-to-implement-one-to-one-one-to-many-and-many-to-many-relationships-while-de