如何找到没有添加任何分类单元的所有疯狂产品?
如果我运行Spree::Product.first.taxons
,我会获得ActiveRecord::Associations::CollectionProxy
产品所含的一系列分类单元,但如何找到此数组为空的所有产品?
我试过了
Spree::Product.where(taxons: nil)
但是这返回了
ActiveRecord::StatementInvalid: PG::UndefinedColumn: ERROR: column spree_products.taxon_id does not exist
答案 0 :(得分:1)
Spree::Product.left_outer_joins(:taxons).where('taxons.id IS NULL')
答案 1 :(得分:0)
Spree::Product.ids - Spree::Classification.pluck(:product_id)
返回所有产品ID的列表,没有任何类型的产品ID。