2017-03-03 61 views
0

如何找到所有没有添加taxons的大礼包?Spree找到没有任何taxons的产品

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

回答

1

Spree::Product.left_outer_joins(:taxons).where('taxons.id IS NULL')

+0

这给了错误的ActiveRecord':: StatementInvalid:PG :: UndefinedTable:错误:缺少FROM子句条目表 “分类群”' – Qwertie

+0

有没有所谓的分类单位的表? – Joe

+1

发现问题,表是“spree_taxons”,所以'taxons.id IS NULL''必须是''spree_taxons.id IS NULL'' – Qwertie

0
Spree::Product.ids - Spree::Classification.pluck(:product_id) 

返回所有产品ID的列表,而其作品不够好任何类群。