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 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 12/4/06, Giant Cranes <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > 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?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, > GiantCranes > > -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Max Muermann wrote:> On 12/4/06, Giant Cranes <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> 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, > MaxThanks 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}) -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> 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. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---