Skip to content

Instantly share code, notes, and snippets.

@michaelminter
Last active January 7, 2016 19:44
Show Gist options
  • Save michaelminter/7256737702ece145c7e2 to your computer and use it in GitHub Desktop.
Save michaelminter/7256737702ece145c7e2 to your computer and use it in GitHub Desktop.
Ruby on Rails arel outer left join
problem = Problem.select('problems.*, COUNT(problem_questions.id) AS problem_question_count')
.joins(Problem.arel_table.join(ProblemProblemQuestion.arel_table, Arel::Nodes::OuterJoin).on(ProblemProblemQuestion.arel_table[:problem_id].eq(Problem.arel_table[:id])).join_sources)
.joins(ProblemProblemQuestion.arel_table.join(ProblemQuestion.arel_table, Arel::Nodes::OuterJoin).on(ProblemQuestion.arel_table[:id].eq(ProblemProblemQuestion.arel_table[:problem_question_id]).and(ProblemQuestion.arel_table[:public].eq(true))).join_sources)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment