我有這個模式MySQL錯誤在更新中的一個屬性連接表
product.rb:
has_many :families_products
has_many :families, :through => :families_products
family.rb:
has_many :families_products
has_many :products, :through => :families_products
families_product.rb:
belongs_to :product
belongs_to :family
和families_product
表我有一個屬性price
,當我試圖在創建後更新它會引發錯誤。
1.9.3p0 :027 > family_product = FamiliesProduct.first
FamiliesProduct Load (0.9ms) SELECT `families_products`.* FROM `families_products` LIMIT 1
=> #<FamiliesProduct family_id: 1, product_id: 1, created_at: "2012-09-10 12:31:54", updated_at: "2012-09-10 12:31:54", points: nil>
1.9.3p0 :028 > family_product.points = 2
=> 2
1.9.3p0 :029 > family_product.save
(0.2ms) BEGIN
(0.7ms) UPDATE `families_products` SET `points` = 2, `updated_at` = '2012-09-10 12:53:05' WHERE `families_products`.`` IS NULL
(0.1ms) ROLLBACK
ActiveRecord::StatementInvalid: Mysql2::Error: Unknown column 'families_products.'
in 'where clause': UPDATE `families_products` SET `points` = 2,
`updated_at` = '2012-09-10 12:53:05' WHERE `families_products`.`` IS NULL
我看到生成的查詢有一個錯誤,所以任何線索?
你創建的family_product對象沒有id列。你把它作爲FamilyProduct模型的主鍵 – Mohanraj
是的,我認爲在這,但連接表不應該有一個主鍵我猜。除了那個之外還有其他解決方案嗎? – Aboelnour