I am new to ruby on rails. I have created a many-to-many association and a migration, such as follows:
in Foo
model:
has_and_belongs_to_many bars
in Bar
model:
has_and_belongs_to_many foos
and the migration for join table has the following content:
def change
create_table :foos_bars, id: false do |t|
t.references :foo
t.references :bar
end
end
Now I see that the association should be one-to-many as: foo has many bars
.
I don't know if I have generated controllers after the above migration, but I know that the file of the above migration is the last one that was created in the migrate folder. Also I have not made any connection yet between any foo and any bar.
Can I do the following to start fresh (change the association and also remove the file of the migration):
use 'rake db:rollback'
delete the file of the join table migration (i.e. timestamp_create_bars_foos.rb file)
change the 'has_and_belongs_to_many' in foo to 'has_many', and in bar to 'belongs_to'
run: 'rails generate migration CreateFoosBars'
run: 'rake db:migrate'
If not, what can I do to make the above modification for the association?
Thanks in Advance!