Wednesday, January 13, 2010

'Include' in rails query

For getting a datum from 2 tables, I have used include as follows,


belongs_to :user


has_many :admins

There was a condition that i have to sort names of admins, where the names of admins will be in user table.


Admin.find(:all, :include=>"user", :order => "")

I felt this easy than sqls, & interesting

1 comment:

Gogolinek said...

Hmmm it looks really nice. I'm just starting with RoR. I can share some opinion later.

Regards, PaweĊ‚ Wojciechowski
Outsourcing IT - Konopnickiej.Com