如何定义仅具有特定属性标签的产品(Spree,Rails)

时间:2018-03-20 14:46:21

标签: ruby-on-rails postgresql spree

我有一个自定义的Spree应用程序。我需要查询具有相关Spree :: Property

的Spree :: Products

我有一个'属性'名称"评级"仅限某些产品,但我无法正确查询这些产品。我现在拥有的是:

Spree::Product.joins(:properties).where(:property_name.downcase == "rating")

但这只会拉动所有具有任何关联属性的产品。

Spree :: Property -

Spree::Property(id: integer, name: string, presentation: string, created_at: datetime, updated_at: datetime)

1 个答案:

答案 0 :(得分:0)

刚刚在Spree 3.1上测试过。您可以从产品或属性模型中执行此操作。

Spree::Product.joins(:properties).where(spree_properties: {name: "rating"})

Spree::Property.where(name: "rating").first.products

*您必须修改代码以使用downcase字符串。