これらは私のモデルです:
class Product
has_many :line_items
has_many :orders, :through => :line_items
end
class LineItem
belongs_to :order
belongs_to :product
end
class Order
has_many :line_items
has_many :products, :through => :line_items
end
schema.rb から:
create_table "line_items", id: false, force: true do |t|
t.integer "order_id"
t.integer "product_id"
t.integer "quantity"
t.datetime "created_at"
t.datetime "updated_at"
end
Rails 4 にアップグレードしたところ、結合テーブルが機能しなくなりました。実行すると@order.line_items
、「モデル LineItem のテーブル line_items の不明な主キー」という例外がスローされます。@order.products
期待どおりに動作します。
line_items テーブルを削除して再作成しようとしました。また、protected_attributes gem をインストールしようとしましたが、何も変わりませんでした。
これがトレースです。