Can I sort a list of objects by a property of an associated object?
For example with the following class
class RosterSlot < ActiveRecord::Base
belongs_to :event
belongs_to :skill
belongs_to :person
end
I want to do something like
RosterSlot.find(:all, :order => skill.name)
which means activerecord needs to do a join and order.
Any ideas?
Yes, you can use the :include option to do the join.
The :order option takes a SQL fragment, so skills is a reference to the plural database table name.
The :include takes an array of Active Record Associations.
See http://www.railsbrain.com/api/rails-2.3.2/doc/index.html?a=M002313&name=find for more info.