Activerecord 怎么实现 left join 的 on 后面加更多条件?
class Maker < ApplicationRecord
has_many :cars
scope :with_cars, -> { eager_load(:cars) }
end
class Car < ApplicationRecord
bolongs_to :maker
end
当我用 makers = Maker.with_cars 时有没有办法传参数给这个scope,
并且得到类似以下的SQL,我希望能给on多加几个条件
SELECT
....
FROM makers
LEFT OUTER JOIN cars
ON makers.id = cars.maker_id
AND cars.company_id = '我传的参数1'
AND cars.status = '我传的参数2'
WHERE
.....