I have a table, folders that I want some other tables to reference, so far my migration script looks like this:
create_table :folders do |t|
t.timestamps
end
....
change_table table1 do |t|
t.references :folders
end
change_table table2 do |t|
t.references :folders
end
change_table table3 do |t|
t.references :folders
end
change_table table4 do |t|
t.references :folders
end
Since I'm doing essentially the same thing to each table, is there a more concise and maintainable way to write this?
Thanks
Try to do this:
[table1, table2, table3, table4].each do |tbl|
change_table tbl { |t| t.references :folders }
end
I hope you don't name tables with pattern table{#n} and give them good names in your actual code :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With