将数组传递给范围

时间:2018-01-17 17:58:35

标签: mysql ruby-on-rails activerecord scope

android:label="Name You Want Here"

scope :colored_product, -> (color) {joins(:properties).where("properties.description=?",color)} 将找到所有产品的属性描述为“红色”。

我想找到property.description为“red”或“blue”的产品。即

Product.colored_product("red")

1 个答案:

答案 0 :(得分:1)

这应该适合你。

scope :colored_product, -> (color) {joins(:properties).where("properties.description in (?)", color)}
Product.colored_product(["red", "blue])

来源:http://guides.rubyonrails.org/active_record_querying.html#subset-conditions

相关问题