How to Sort by a column from another table


#1

I need to create a list of users sorted by division. How do I sort User
table by Division name? I can only get it to sorted by division_id.

Part of my code is shown below:

sort = case params[‘sort’]
when “id” then “id ASC”
when “email” then “email ASC”
when “division_id” then “division_id ASC”

@users = User.find(:all, :order => sort)


#2

@users = User.find(:all, :order => sort)

@users = User.find(:all, :include => :division, :order =>
‘divisions.name’)

(assuming Division has a ‘name’ field)