ruby on rails - Where query with uniqueness -


i want query answers correct = true , grab 1 answer if have same question id. trying uniq or distinct.

@answers = answer.where(id: params[:answer_ids]) @correct_answers = @answers.where(correct: true, question_id: distinct).count 

how grab 1 answer of answers same question_id?

try this:

@answers = answer.joins(:question).where(id: params[:answer_ids]) @correct_answers = @answers.where(correct: true).distinct(:question_id) 

Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -