Forum: Ruby on Rails How to Sort by a column from another table

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Sunny B. (Guest)
on 2009-04-02 05:10
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)
Philip H. (Guest)
on 2009-04-02 06:36
(Received via mailing list)
> @users = User.find(:all, :order => sort)

@users = User.find(:all, :include => :division, :order =>

(assuming Division has a 'name' field)
This topic is locked and can not be replied to.