狂欢发现没有任何分类的产品

时间:2017-03-03 00:54:42

标签: ruby-on-rails rails-activerecord spree

如何找到没有添加任何分类单元的所有疯狂产品?

如果我运行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

2 个答案:

答案 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。