Forum: Ruby on Rails Multiple Join Tables between Two Tables? Another solution?

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
22825eb1ad76856735f1c2d0350656d9?d=identicon&s=25 rcgann (Guest)
on 2007-06-25 20:36
(Received via mailing list)
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.
588ab1c0a5610a7e160a3b101abb91e6?d=identicon&s=25 Michael Latta (Guest)
on 2007-06-25 20:52
(Received via mailing list)
I would recommend against having 4 tables for joins.  Just have
one :through association with a model that has acts_as_list to order

22825eb1ad76856735f1c2d0350656d9?d=identicon&s=25 Robert Gann (Guest)
on 2007-06-25 21:11
(Received via mailing list)
Thanks!  I've been using Agile Web Development for Rails as a reference.
solution was inspired by a section entitled Using Models as Join Tables.
had noticed that the :through option was mentioned on the next page, but
not see how to use that.

I'll give it a try.  Thanks again!  Having four join tables just did not
seem right.
This topic is locked and can not be replied to.