rails g migration CreateJoinTable zombie:index role:index
這就造成這種遷移:有效地創建一個連接表遷移
class CreateJoinTable < ActiveRecord::Migration
def change
create_join_table :zombies, :roles do |t|
t.index [:zombie_id, :role_id]
t.index [:role_id, :zombie_id] # I'd be happy if it didn't have this!
end
end
end
,移民幾乎是有,但爲什麼我有四個指標,而不是兩個?在我的generate命令中,它是否指定爲已經存在的索引創建額外的兩組索引?
供參考:http://edgeguides.rubyonrails.org/active_record_migrations.html#creating-a-join-table 也是這樣: http://edgeguides.rubyonrails.org/active_record_migrations.html#creating-獨立遷移(本部分的最後部分) – sixty4bit