skip to Main Content

Why the count alias column is not returned as part of ActiveRecord_Relation? – Postgresql

I have two tables. StudentGroup and StudentGroupsMembers. StudentGroup.id = StudentGroupMembers.group_id is the foreign key relation. sg = StudentGroup.joins(:student_group_members).select(" student_groups.id, student_groups.name, count(student_group_members.id) as cnt ").group('student_group_members.group_id, student_groups.name, student_groups.id').where(id: [3,4,5,6,6,7,7,8,8]).where("student_group_members.member_type='ra'") This return ActiveRecord_Relation [#<StudentGroup:0x00007fc11253d088 id: 3, name: "Blah">, #<StudentGroup:0x00007fc11253cc78 id: 4, name: "Foo">,…

VIEW QUESTION
Back To Top
Search