私はRails 2.3.2を実行しており、次のことを行っています:
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 )
どうすればこれを機能させることができますか?
HBTM に関する Rails のドキュメントには、次のように書かれています。
警告: いずれかのクラスのテーブル名を上書きする場合、動作させるには、has_and_belongs_to_many 宣言の下で table_name メソッドを宣言する必要があります。
これは何を意味するのでしょうか?