我想使用构面按属性过滤产品,或者换句话说,一次跨多个属性选择多个值。
我决定手动构建查询,但是下面的 SQL 产生的结果比我预期的要少。如何更改它以包含所有产品?
SELECT COUNT(DISTINCT "spree_products"."id") FROM "spree_products"
LEFT OUTER JOIN "spree_product_properties" ON "spree_product_properties"."product_id" = "spree_products"."id"
WHERE
("spree_product_properties"."value" in ('lacoste', 'fred perry') AND "spree_product_properties"."property_id" = 161337574)
AND
("spree_product_properties"."value" in ('socks', 'shirts') AND "spree_product_properties"."property_id" = 905834903)