2017-06-04 7 views
0

したがって、テーブルuserslooking_for_optionsの間にジョインテーブルを作成しようとしています。Rails create join tableのインデックス名が長すぎます

これは私のマイグレーションファイルです:

class CreateJoinTableOptionsUsers < ActiveRecord::Migration[5.0] 
    def change 
    create_join_table :looking_for_options, :users do |t| 
     t.index [:looking_for_option_id, :user_id] 
     t.index [:user_id, :looking_for_option_id] 
    end 
    end 
end 

しかし、私はこのエラーを取得しています:

Index name 'index_looking_for_options_users_on_looking_for_option_id_and_user_id' on table 'looking_for_options_users' is too long; the lim it is 64 characters

join tableため、rails大会はTable_A_Name_Table_B_Nameであり、その列は、同様の規則に従うことを知っTable_A_idおよびTable_B_id

joint tableに短い列名を指定するにはどうすればrails多対多の関連付けを中断しないのですか?

更新:

私は私だけではなく、インデックスに別の名前を付けることができることがわかりました。しかし、railsの多対多関連が実際にそれを利用するでしょうか?

class CreateJoinTableOptionsUsers < ActiveRecord::Migration[5.0] 
    def change 
    create_join_table :looking_for_options, :users do |t| 
     t.index [:looking_for_option_id, :user_id], name: 'option_user' 
     t.index [:user_id, :looking_for_option_id], name: 'user_option' 
    end 
    end 
end 

答えて

0

... will rails's many-to-many association actually utilize it?

インデックスを使用するかどうかの選択は、データベースオプティマイザによって行われ、レールによって影響されません。データベースによって課せられた制約内で、好きな名前を付けることができます。

関連する問題