2

多対多の関連付けに build を使用したい場合、コントローラーで次のエラーが発生します。

不明な属性: fte_report_option_id

私のコントローラーで:

def edit_clients_reports
@fte_report_option = FteReportOption.find(params[:id])
@fte_report_option.fte_report_client_options.build
end

私の最初のモデルには、次のものがあります。

class FteReportOption < ActiveRecord::Base

has_many :fte_report_client_options, :dependent => :destroy
has_many :clients, :through => :fte_report_client_options
end

私の2番目のモデルでは:

class FteReportClientOption < ActiveRecord::Base
self.primary_key = "client_report_id"

所属先 :fte_report_option, :foreign_key => :option_id, :class_name => "FteReportOption" 所属先:client, :foreign_key => :client_id, :class_name => "クライアント"
end

そして私の3番目のモデル:

class Client < ActiveRecord::Base
set_primary_key "client_id"

has_many :fte_report_client_options, :dependent => :destroy
has_many :fte_report_options, :through => :fte_report_client_options

結合テーブルの移行には、次のものがあります。

create_table :fte_report_client_options, :primary_key => "client_report_id", :force => true do |t|
t.integer :option_id
t.integer :client_id
t.timestamps
end

何が起こっているか知っている人はいますか?

ご協力いただきありがとうございます

4

1 に答える 1

0

移行で、次の行を変更します。

t.integer :option_id

に:

t.integer :fte_report_option_id
于 2012-10-21T00:22:41.577 に答える