Rails help needed - code is generating too many SQL statements

Associate
Joined
18 Oct 2002
Posts
268
Location
Essex
I have a line of code that is running really slow because it is generating loads of SQL statements.

<%= select 'user', 'manages_office_id' , Office.find(:all).collect {|d| [ d.name + ', ' + d.organisation.name, d.id ] } %>

I have 'offices' that each belong to 'organisations' and this code is producing a dropdown of all offices (but with the organisation name attached).

The d.organisation.name is generating a seperate SQL requests for each office.

Any ideas what could be done to stop hitting the database so much?
 
Back
Top Bottom