Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add extra data to the join table - Rails

I am developing an application, with a years model and a courses model. Currently there is a has_and_belongs_to_many relationship linking these with a courses_years table, however I would like to store an extra field in the courses_years table.

The new field is a boolean value called "compulsory".

Is there an easy or nice way of doing this?

like image 833
Jack Avatar asked Feb 24 '10 17:02

Jack


1 Answers

Switch to using a :has_many => :through association, which is specifically designed for when you need a join model. There are more details in the ActiveRecord Associations Rails Guide.

like image 56
John Topley Avatar answered Oct 13 '22 16:10

John Topley