How do I do a script/generate migration
to create a join table for a has_and_belongs_to_many
relationship?
The application runs on Rails 2.3.2, but I also have Rails 3.0.3 installed.
code generationhas-and-belongs-to-manymigrationruby-on-rails
How do I do a script/generate migration
to create a join table for a has_and_belongs_to_many
relationship?
The application runs on Rails 2.3.2, but I also have Rails 3.0.3 installed.
Best Answer
Where:
and
for rails 4:
for rails 3:
for rails < 3
(note the table name lists both join tables in alphabetical order)
and then for rails 3 and below only, you need to edit your generated migration so an id field is not created: