activerecord - Rails, scope, OR and joins -
i have scope:
includes(:countries).where("profiles.sector = :sector or advices.sector = :sector", :sector => sector)
it produces following sql:
select `profiles`.* `profiles` inner join `advices` on `advices`.`profile_id` = `profiles`.`id` (profiles.sector = 'forestry_paper' or advices.sector = 'forestry_paper')
(yes have country in profile
, in country
model)
unfortunately, or
seems fail:
it doesn't render profile having proper sector no related advice. thoughts?
you doing inner join, requires profiles have corresponding advice. try following instead:
profile .joins("left join advices on advices.profile_id = profiles.id") .where("profiles.sector = :sector or advices.sector = :sector", :sector => sector)
this include profiles have no advices.
Comments
Post a Comment