0
我運行的Rails 2.3.2和做:Rails的HBTM join_table overwirting table_name的
class StandardWidget < ActiveRecord::Base
has_and_belongs_to_many :parts, :join_table => "widgets_parts", :association_foreign_key => "widget_custom_id"
end
class Part < ActiveRecord::Base
has_and_belongs_to_many :widgets, :join_table => "widgets_parts", :association_foreign_key => "part_custom_id"
end
p = StandardWidget.find(5)
p.widgets
並且得到錯誤
ActiveRecord::StatementInvalid: Mysql::Error: Unknown column 'widgets_parts.standard_widget_id' in 'where clause': SELECT * FROM `widgets` INNER JOIN `widgets_parts` ON `parts`.part_custom_id = `widgets_parts`.part_custom_id WHERE (`widgets_parts`.standard_widget_id = 5)
我怎樣才能得到這個工作?
的Rails documentation on HBTM說:
警告:如果你既覆蓋類的 表名,表名 方法必須爲了工作宣告 任何has_and_belongs_to_many 聲明下方。
這是什麼意思?
工作!謝謝! – ma11hew28 2010-12-09 16:44:15