Skip to content

Instantly share code, notes, and snippets.

@jeffnv
Created October 4, 2013 23:08
Show Gist options
  • Save jeffnv/6834333 to your computer and use it in GitHub Desktop.
Save jeffnv/6834333 to your computer and use it in GitHub Desktop.
def results
responses = Question.joins(<<-SQL)
LEFT OUTER JOIN answer_choices
ON answer_choices.question_id = questions.id
LEFT OUTER JOIN responses
ON answer_choices.id = responses.answer_choice_id
SQL
responses = responses.where("questions.id = ?", self.id)
p responses
responses.group('answer_choices.answer_body').count('responses.id')
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment