I have two classes Building and Room. I want to sort my Room model by the building’s name attribute and then by the room’s room_number attribute. This is essentially what I want to do:
class Room
belongs_to :building
default_scope :order => 'building.name, room_number' # Doesn't work.
end
I just don’t know how to get the association to work. Is there a way to do this in Rails?
You have to JOIN the
buildingstable before you can reference in the order condition.