You are here

order by

Ruby on Rails Order By Using Associated Model

It is very easy to use an 'order by' clause in a model in Ruby on Rails. Supposing you have a Category model it's as simple as doing this:
 
@categories = Category.find(:all, :order => 'title')
 
But what if I need to order by the title of the subcategories after ordering by the categories title?
 
Using the category_id does not work either, because it almost sure that the categories will not be added in alphabetical order, so the command below does not work for me either:
 

Subscribe to RSS - order by