为什么我的迁移中的 create join table 与文档不同?

Why is the create join table from my migration different from the docs?

我想创建一个评级页面:https://nomadlist.com/amsterdam-netherlands

  1. rails g model Rating name user:references

  2. rails g migration CreateJoinTableItemsRatings item rating

我得到:

create_join_table :items, :ratings do |t| t.index [:item_id, :rating_id] t.index [:rating_id, :item_id] end

但是从 docs 我看到:

create_join_table :items, :ratings do |t| t.index :item_id t.index :rating_id end

为什么会有差异?首选哪一个,为什么?

生成器是性能更高(也是首选)的迁移。

这里有一个非常详细的讨论:How to properly index fields on a Rails join table migration?