Association Caching

Hi,

I have a collection of Vehicles which belongs_to a number of entities
such as Manufacturer, Transmission and Fuel. When rendering individual
Vehicles in the collection, I access vehicle.manufacturer.name and
vehicle.transmission.name. Each time I access these properties, some SQL
is equcuted such as:

‘SELECT * FROM manufacturers WHERE (manufacturers.id = 1) LIMIT 1’

As this data is virtually static, is there a way to cache this data and
still use the association vehicle.manufacturer.name?

Thanks,
GiantCranes

On 12/4/06, Giant C. [email protected] wrote:

As this data is virtually static, is there a way to cache this data and
still use the association vehicle.manufacturer.name?

You can instruct AR to retrieve manufacturer and transmission data in
the same SELECT statement as the vehicles:

Vehicle.find(:all, :include=>[:manufacturer, :transmission])

Cheers,
Max

Max M. wrote:

On 12/4/06, Giant C. [email protected] wrote:

As this data is virtually static, is there a way to cache this data and
still use the association vehicle.manufacturer.name?

You can instruct AR to retrieve manufacturer and transmission data in
the same SELECT statement as the vehicles:

Vehicle.find(:all, :include=>[:manufacturer, :transmission])

Cheers,
Max

Thanks for the reply. I tried that, but it seems to be ignored when
using the following:

find(:all,
:readonly => true,
:include => [:counties],
:joins => “INNER JOIN tags_vehicles a ON vehicles.id =
a.vehicle_id”,
:conditions => “a.tag_id IN (#{tags.map.join(’, ')})”,
:group => “vehicles.id HAVING COUNT(vehicles.id) =
#{tags.size}”,
:order => “vehicles.updated_on DESC”,
:page => {:size => page_size, :first => 1, :current => page,
:count => count})

Thanks for the reply. I tried that, but it seems to be ignored when
using the following:

Apologies, I was mistaken. It works a treat.

Thanks.