我正在尝试将arel查询与Product scope结合使用。
p = Spree::Product.arel_table
p1 = Spree::ProductProperties.arel_table
p2 = p1.alias
query = p
.join(p1)
.on(p[:id].eq(p1[:product_id]))
.where(p1[:property_id].eq(5)
.and(p1[:value].eq("10 inches")))
.join(p2)
.on(p[:id].eq(p2[:product_id]))
.where(p2[:property_id].eq(4)
.and(p2[:value].eq("1400")))
现在的问题是,当我尝试将它与base_scope结合使用时会导致错误,这会增加一些其他标准。 base_scope.where(查询)
=> “SELECT \”spree_products \“。* FROM \“spree_products \”WHERE \“spree_products \”。\“deleted_at \”IS NULL AND((SELECT FROM \“spree_products \”INNER JOIN \“spree_product_prop erties \”ON \“spree_products \”。\“id \”= \“spree_product_properties \”。\“product_id \”INNER JOIN \“spree_product_properties \”\“spree_product_properties_2 \”ON \“spree_product s \”。\“id \”= \“spree_product_properties_2 \”。\“product_id \”WHERE \“spree_product_properties \”。\“property_id \”= 5 AND \“spree_product_properties \”。\“value \”= '10英寸'AN D \“spree_product_properties_2 \”。\“property_id \”= 4 AND \“spree_product_properties_2 \”。\“value \”='1400'))“
有没有办法实现这一点,而不是简单的sql?