I've read about how indexes applied to foreign key fields are important for application speed performance, but I've also read contradictory statements about how to set these up. In the structure shown in my model and migration files below:
class Owner < ApplicationRecord
has_many :dogs
end
class Dog < ApplicationRecord
belongs_to :owner
end
create_table :owners do |t|
t.string :full_name
t.string :address
t.timestamps
end
create_table :dogs do |t|
t.string :name
t.string :age
t.string :breed
t.references :owner, foreign_key: true
t.timestamps
end
On the line where I declare my foreign key field:
t.references :owner, foreign_key: true
If I leave it like this, will Rails automatically create a database index for me, or do I need to add one manually by modifying the line to display the code below?
t.references :owner, foreign_key: true, index: true
Or if I do need to add the index manually, do I instead need to declare it with the add_index method in a separate block of code? In which case, what is the point of index: true?
I'm using Rails 5.1.4