I have two entity classes, Student and Committee.
I can not post images, but image of current db design can be found here:
current db design
or in text:
**Committee**
id
name
**students_committees**
stud_id
com_id
**students**
name
gender
grade
students can be in many committees, and a committee has many students.
Now I want to add a leader to committee (a committee can have more than 1 leader).
What is the best way to do this?
- Add another join table:
committee_leaders(stud_id, com_id) - Add extra column to the existing join table:
students_committees(stud_id, com_id, is_leader) - Something else?
I would assume an extra join table is the best choice. We would not need to traverse the entire current join table to find the leaders for a committee. My team does not agree.
My choice would be option 1 if the points 2 and 3 below matter in your case. If not, option 2 is simpler.
Pros (vs option 2):
(as you pointed) you would not need to traverse the entire current join table to find the leaders for a committee. You’ll just join
committeewithcommittee_leaders. (not much difference though, you’ll be just searching a smaller index, the difference may be negligible.)you can easily enforce the constraint that a committee has no more than one leader.
if you want to add other attributes for the leaders, like when the leader was chosen (elected), what other title they gain, etc, you’ll not be filling the
studens_committeestable with columns that will beNULLalmost everywhere.Cons:
leaving the committe would require DELETEs on 2 tables (or 1 with cascading delete in effect).
inserting a new student as leader will require two INSERTs in 2 tables.
changing the leader in a committee will require one DELETE and one INSERT vs 2 UPDATEs (possibly in one statement).