我想查询正确=真的答案,如果他们有相同的问题ID,只抓一个答案。我尝试的是uniq或者不同。
@answers = Answer.where(id: params[:answer_ids])
@correct_answers = @answers.where(correct: true, question_id: distinct).count
你怎么能用同样的问题_id获得任何答案的答案?
答案 0 :(得分:2)
试试这个:
@answers = Answer.joins(:question).where(id: params[:answer_ids])
@correct_answers = @answers.where(correct: true).distinct(:question_id)