Query that joins child model results item erroneously shown multiple times
问题 I have the following models, each a related child of the previous one (I excluded other model methods and declarations for brevity): class Course < ActiveRecord::Base has_many :questions scope :most_answered, joins(:questions).order('questions.answers_count DESC') #this is the query causing issues end class Question < ActiveRecord::Base belongs_to :course, :counter_cache => true has_many: :answers end class Answer < ActiveRecord::Base belongs_to :question, :counter_cache => true end Right now