[Rails] Eager loading problem. Help greately appreciated

Chris evilgeenius at gmail.com
Wed Mar 1 12:43:29 GMT 2006


Each Timesheet has an employee.  An employee has a division and a 
location.
I want to find all the timesheets with a status of 2.  I then iterate 
over the timesheet collection and print the timesheet name, employee 
name, employee divison name, and employee location name.  Like so:

for t in 
Timesheet.find(:all,:conditions=>"status=2",:include=>:employee)
  puts timesheet.date
  puts timesheet.employee.name
  puts timesheet.employee.division.name
  puts timesheet.employee.location.name
end

Adding the ":include=>:employee" to the find preloads all the employees 
BUT it does not preload the division and location.  This query returns 
over 1000 timesheets, so it takes a long time to load each division + 
location.

Any ideas how to preload the Division and Location??

Any help is really appreciated as I'm really stuck,

Thanks in advance,
Chris


-- 
Posted via http://www.ruby-forum.com/.


More information about the Rails mailing list