Sorting has_many relationships


#1

Hi Railers!

I’m building a new website for our bar-foos-league (league for
foosball players who play in bars in Zurich, Switzerland :wink:

Being a bit of a noob when it comes to rails and web development in
general, I’ve come across a few questions. One concerns sorting of a
has_many relationship, for instance.

I’ve got a League model, which has_many TeamConfigs which in turn
belongs_to a Team object. A TeamConfig is basically the
representation of a Team for one season, so the name of the team is
an attribute of the Team model.

What I’d like to do is something like this:

class league
has_many :team_configs, :order => ‘team.name’
end

Of course, this doesn’t work. So I’m wondering if I’m missing some
obvious way to do this, or if I have to sort my TeamConfigs with
ruby. Any insight would be much appreciated.

Cheers,
greg