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) -

xcode - Swift Playground - Files are not readable -

jboss7.x - JBoss AS 7.3 vs 7.4 and differences -