Count games

I'm making a site that will display statistics. For my question I have two models, a School and a Team.

A team has an integer, games.

What is the best way to output for each school, the total number of games for all the school's teams?

edberner wrote:

I'm making a site that will display statistics. For my question I have two models, a School and a Team.

A team has an integer, games.

What is the best way to output for each school, the total number of games for all the school's teams?

If this is a database or model question, sufficient use of has_many directives will enable a line like school.team.map{|t| [t.name, t.games.count] }

If it's a view question, the answer is some combination if <dl> or <table> tags, to display each school, team, and game count.

So nobody here can tell what the "best" way is. Try asking a more specific question!

This worked. for school in @schools      for team in school.teams        school.games += team.games      end    end