为什么default_scope用于保存

时间:2013-04-03 21:30:54

标签: ruby-on-rails spree

为Spree :: Product添加了default_scope,以对spree网站的主页面进行排序,范围为default_scope :include => :product_taxons, :order => "spree_product_taxons.position"。对此进行排序,但是当我尝试更新产品时,我收到以下错误

ActiveRecord::StatementInvalid: Mysql2::Error: Unknown column 'spree_product_taxons.position' in 'order clause': UPDATE `spree_products` SET `count_on_hand` = 100 WHERE `spree_products`.`id` = 108 ORDER BY spree_product_taxons.position`

首先,为什么要尝试订购更新? 而且,该领域确实存在

Spree::ProductTaxon
=> Spree::ProductTaxon(id: integer, created_at: datetime, updated_at: datetime, product_id: integer, taxon_id: integer, position: integer)

1 个答案:

答案 0 :(得分:0)

该字段存在于spree_products_taxons中,但不在spree_products中,因此出现错误。更新中未提及spree_products_taxons include