Rails5 关联表格搜索

创建: 2017/08/13

 
other_type_car = Car.joins(:car_type).active.find_by(car_type: car_type)
 
@recommend_cars = Car.joins(:region).active.where('regions.region_name = :region_name AND total_price >= :bottom AND total_price <= :top', region_name: @car.region.region_name, bottom: @car.total_price - 300_000, top: @car.total_price + 300_000)
 
注意: 是joins, 搜索条件里用复数
Model.joins(:sample).where('samples.item = :item', item: 123)

 

posted @ 2017-08-13 01:06  懒虫哥哥  阅读(114)  评论(0编辑  收藏  举报