Rails 4 introduced a feature for generating join table migrations:
bin/rails generate migration CreateTeamsUsersJoinTable team user
This re
I would have to say that the intention behind this is to let you choose the strategy that fits you better. That is usually a decision with two criteria
So they can not make that decision for you and add the indexing overhead as a convention.
In order to make that decision you need to know how you intend to query your database. In MySQL composite indexes can be of use for a set of queries. multiple-column index
An index on column_a, column_b, column_c
will be used for queries on
column_a
alonecolumn_a
and column_b
togetherSo there is a difference between
t.index [:team_id, :user_id]
and
t.index [:user_id, :team_id]
the actual full set of indexes that you 'll need is
t.index [:team_id, :user_id]
t.index :user_id
or
t.index [:user_id, :team_id]
t.index :team_id
In order to handle with an index all three cases.
if you find your app to use more frequently queries like
user.teams
which translate to
select * from teams where user_id = X
an index on user_id
(or user_id, team_id
) can be handy
so t.index [:user_id, :team_id]
should be your choice