What is the correct way to design this database?
Here is how I have my tables set up:
I have a many to many relationship between a table called teachers and a table called instruments. I then have a bridge table connecting the two. I would like to associate another table with the BRIDGE table. Meaning the instrument/teacher combination. That table would have 3 rows specifying what level of playing a teacher can teach (ie. Beginner, intermediate, advanced). Seems like I should set up the bridge table to have teacher_id, instrument_id AND level_id, but I don’t know if this is the conventional way to do it.
I am using mysql and cakephp, and I haven’t found anything in the documentation about the HABTM associations about having an extra field in the bridge table. Just want to make sure I’m doing it correctly.
If that’s what your data calls for, and it sounds like it does, then go for it.
Basically, as you noted, you’d have a three-part key:
Which means that a teacher could teach guitars at beginner and advanced, piano at intermediate and beginner, and another teacher could teach piano at all three levels and oboe at beginner … sounds good.
Incidentally, the bridge table is also known as an
intersectorintersectiontable.