select students.shirt as size, count(students.shirt) as quantity
from students, memberships, teams
where students.shirt is not NULL
and students.id = memberships.student_id
and memberships.team_id = teams.id
and teams.id = #{team.id}
group by students.shirt
- Teams has many students through memberships
- Students has many teams through memberships
- Memberships belong to teams, students
Whoops, let me try this differently.
Season
Team
Membership
Student
All I have is a season object. So I'm iterating over the season.teams collection and passing the team.id into this query. That's why I'm joining on the teams table. Also, the report is run once for each team, so that's where the results get displayed under.