Multiple Join Tables between Two Tables? Another solution?

I’m a RoR newbie, so I’d like to be sure I’m on the right track. I’m
coding an application where I have one table with students and another
table with first year seminars (fyss). The students have listed 4 fys
preferences in order.

Since the FYS seminars are listed in order and we are trying to give
student their first choices, I cannot use a 1 - n relationship between
table students and table fyss.

My design uses a models as join tables. It works as follows:

  • I have a table students with an id and a name.
  • I have a table fyss with an id and a course title.
  • I have a table fyschoice1s with an id, a student_id, and a fys_id.
  • I have a table fyschoice2s with an id, a student_id, and a fys_id.
  • I have a table fyschoice3s with an id, a student_id, and a fys_id.
  • I have a table fyschoice4s with an id, a student_id, and a fys_id.

The last four tables have a 1 - 1 relationship between, for example,
students and fsychoices1 and between fyss and fyschoices1.

Is this the best solution? I’d deeply appreciate any guidance.
Thanks in advance.

I would recommend against having 4 tables for joins. Just have
one :through association with a model that has acts_as_list to order
them.

Michael

Thanks! I’ve been using Agile Web D. for Rails as a reference.
My
solution was inspired by a section entitled Using Models as Join Tables.
I
had noticed that the :through option was mentioned on the next page, but
did
not see how to use that.

I’ll give it a try. Thanks again! Having four join tables just did not
seem right.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs