unknown attribute: id on build
When I want to use build for a many-to-many through association, I get the following error in my controller:
unknown attribute: fte_report_option_id
In my controller:
def edit_clients_reports
@fte_report_option = FteReportOption.find(params[:id])
@fte_report_option.fte_report_client_options.build
end
In my first model, I have:
class FteReportOption < ActiveRecord::Base
has_many :fte_report_client_options, :dependent => :destroy
has_many :clients, :through => :fte_report_client_options
end
In my second model:
class FteReportClientOption < ActiveRecord::Base
self.primary_key = "client_report_id"
belongs_to :fte_report_option, :foreign_key => :option_id, :class_name => "FteReportOption" belongs_to :client, :foreign_key => :client_id, :class_name => "Client"
end
And my third model:
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
In my migration for the join table, I have:
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
Is anyone know what's happen?
Thanks for your help
In your migration, change line:
t.integer :option_id
to:
t.integer :fte_report_option_id
链接地址: http://www.djcxy.com/p/35956.html
上一篇: 在rails 3上找不到没有ID的UserSession
下一篇: 未知属性:构建时的id