Using :group and :order with find()

Not quite sure what you’re looking for, but the first thing you might want to do is

to declare ‘Country’ as:

class Country < ActiveRecord::Base
has_many :states, :order => ‘name’

Then saying

Country.find(:all, :include => :state)

will load all the state/country pairs in one query.

The SQL terminology is not 100% transparent - “GROUP BY” is used to create
partial results when using aggregate functions. A simple example would be using
SUM() to create totals - without grouping, the result is the total of all the selected

rows. With grouping, the result will be a set of subtotals.

Hope this helps,

Matt Jones
President/Technical Director, Acme Art Company,