私の質問は簡単ですが、私は明確な答えを見つけることができませんでした。belongs_to/has_many関係の移行でadd_indexを使用する必要がありますか? (Rails 3.2、Active Record)
私は毎日お得なRailsアプリをビルドします。
各取引は各製品はRails Guidesから契約2.3をFolowing
に属している多くの製品(has_manyの)
を持って、私は私の移行でこれを使用します:
class CreateDeal < ActiveRecord::Migration
def change
create_table :deals do |t|
t.string :name
t.timestamps
end
create_table :products do |t|
t.belongs_to :Deal
t.timestamps
end
end
end
Rails/activeレコードは自動的にProduct Tableに追加されます。ac olumn deals_idは正しいですか?
マイ・マイグレーションadd_index
を追加することによって、この「deals_id」列に手動で索引を追加する必要がありますか(または後述のように)、私が設定したbelongs_to/has_many関係のため「自動」ですか?
create_table :products do |t|
t.belongs_to :Deal
t.timestamps
add_index :products, :deals_id
end
't.belongs_to:Deal'は' t.belongs_to:deal'となるべきではありません –