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
Post a Comment