Forum: Ruby on Rails ordering with eager loading

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
94a7a55f37d81f6b3055ae60bd81790f?d=identicon&s=25 Felipe Gallois (Guest)
on 2008-11-19 07:31
(Received via mailing list)
I'm trying to order my results by what I got with eager loading.

there is a bit of code about what i want

@study_class = StudyClass.find(:all, :include => :teacher)

it is associated with an id, and i want to order my result by the
teachers'
name, which is just inside the teacher table that is loaded there.

is it possible or will i have to reorder it with ruby code?

thanks!

--
gallois
aka Felipe Gallois
blog: www.gallois.com.br/blog
fanglib homepage: www.gallois.com.br/fanglib
2d8132658d56e51f19ace1c68e48b6aa?d=identicon&s=25 Thorsten Mueller (thorsten)
on 2008-11-19 10:26
(Received via mailing list)
>
> is it possible or will i have to reorder it with ruby code?
>

Can be done like that:

@study_class = StudyClass.find(:all, :include => :teacher, :order =>
"teachers.name ASC")

(since :order takes pure SQL, it must be the table name in plural
as used in the database)
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2008-11-19 10:27
(Received via mailing list)
On 19 Nov 2008, at 01:05, Felipe Gallois wrote:

> is it possible or will i have to reorder it with ruby code?
:order => 'teachers.something'

Fred
94a7a55f37d81f6b3055ae60bd81790f?d=identicon&s=25 Felipe Gallois (Guest)
on 2008-11-19 12:58
(Received via mailing list)
On Wed, Nov 19, 2008 at 07:26, Frederick Cheung
<frederick.cheung@gmail.com>wrote:

> > it is associated with an id, and i want to order my result by the
> > thanks!
> >
>
perfect! worked like a charm! thank you very much guys!

cheers!

--
gallois
aka Felipe Gallois
blog: www.gallois.com.br/blog
fanglib homepage: www.gallois.com.br/fanglib
This topic is locked and can not be replied to.