On 6/22/05, Jeff Cole <cole.jeff-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> Is it possible to order by association? For example, in this case: "
> Foo.find(:all, :include => :bar) ", is it possible to somehow order
> by Bar.name? The option ":order" only lets you order by
explicit SQL.
You have two options:
1) Order with SQL
:order=>"bars.name asc"
2) Order with Ruby code
Foo.find(:all, :include=>:bar).sort {|l,r| l.name <=> r.name }
> thanks,
> Jeff
>
>
> _______________________________________________
> Rails mailing list
> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
--
Cheers
Koz