活动记录和运营商

时间:2016-06-26 18:13:10

标签: sql ruby-on-rails activerecord

如何将其转换为一个WHERE语句?我想查找房产是公寓的记录,也可以出售。

def apartment
    @apartments_for_sale = Property.where(for_sale: true)
    @real_apartments = @apartments_for_sale.where(apartment: true)
end

非常感谢!

1 个答案:

答案 0 :(得分:2)

你应该可以这样做:

def apartment
    @apartments = Property.where(for_sale: true, apartment: true)

     #OR via method chaining:

    @apartments = Property.where(for_sale: true).where(apartment: true)
end