Cannot use group with has_many through in Rails 5
问题 I have the following associations: class Student < ApplicationRecord has_many :people_schools has_many :schools, through: :people_schools end class PeopleSchool < ApplicationRecord belongs_to :student belongs_to :school end class School < ApplicationRecord has_many :people_schools has_many :students, through: :people_schools end I am trying to get a list of students organized by their school. I have tried the following: Student.joins(:schools).all.group('schools.name') but I get the following