These are my models:
class Product has_many :line_items has_many :orders, :through => :line_items end class LineItem belongs_to :order belongs_t
In model add the following:
self.primary_key = [:order_id, :product_id]
and I think it would be wise to ensure that there's an index on those columns.
index
You may create one with following migration:
add_index :line_items, [:order_id, :product_id]