My question is quite simple but I failed to find a clear answer.
I build a daily deals Rails app.
Each deal has many products (has_many)
Each product belongs to a deal
Folowing 2.3 from Rails Guides, I'll use this in my migration:
class CreateDeal < ActiveRecord::Migration
def change
create_table :deals do |t|
t.string :name
t.timestamps
end
create_table :products do |t|
t.belongs_to :Deal
t.timestamps
end
end
end
Automatically, Rails/active records will add in the Product Table a column deals_id right?
Do I need to add an index on this deals_id column manually (like below) by adding to my migration add_index
or is it done "automatically" because of the belongs_to/has_many relationship I have set?
create_table :products do |t|
t.belongs_to :Deal
t.timestamps
add_index :products, :deals_id
end