레일 (5)에서 나는 다음과 협회를 통해 has_many와 그룹을 사용할 수 없습니다 : 나는 학교에 의해 조직 된 학생의 목록을 얻기 위해 노력하고는
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
. 나는 시도 다음
Student.joins(:schools).all.group('schools.name')
그러나 나는 다음과 같은 오류 얻을 : 나는이 문제를 해결하려면 어떻게
ActiveRecord::StatementInvalid: PG::GroupingError: ERROR: column "students.id" must appear in the GROUP BY clause or be used in an aggregate function
를?
학생은 많은 학교 ('has_many : 학교')의 학생이거나 항상 단 하나의 학생 ('has_one : 학교')이어야합니까? 아니면 조인 테이블이없는 'belongs_to : school'입니까? – ulferts