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

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -