条款平等和条件相同的条款4

时间:2015-03-18 06:35:18

标签: mysql ruby-on-rails ruby-on-rails-4

我可以在RoR 4中发表如下声明:

@vendors = Vendor.includes(:business).where(:business_id=>@business.id,:city_id=>city,:activated=>"1",["business.business_name LIKE ?","%#{params[:search]}%"]).page(params[:page]).per_page(10)

如果没有,那我该怎么办?

1 个答案:

答案 0 :(得分:1)

不,你不能这样做,但你可以链接.where()个电话,即。

.where(business_id: @business.id).where("businesses.business_name LIKE ?", "%#{params[:search]}%")

请注意,您需要包含.references(:business)才能确保执行LEFT JOIN

Vendor.includes(:business).references(:business).where(business_id:@business.id, etc..).where('businesses.business_name LIKE ?", "%#{params[:search]}%")