I noticed that when you use an include on an association, for each record that does not have an association corresponding to the included association, an extra sql statement will be executed in order to find the record which you already know does not exist because it would have otherwise been fetched by the include already. To avoid these extra db round trips I would like to check if the association has already been fetched before I call on the association and let rails attempt to lazy load it. Does anyone know how I can do this? Thanks, Kris -- 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 -~----------~----~----~----~------~----~------~--~---
Mark Reginald James
2006-Nov-17 18:20 UTC
Re: Check if associations are loaded before lazy loading them?
Kris wrote:> I noticed that when you use an include on an association, for each > record that does not have an association corresponding to the included > association, an extra sql statement will be executed in order to find > the record which you already know does not exist because it would have > otherwise been fetched by the include already.Rails 1.2 will cache nil association values. -- We develop, watch us RoR, in numbers too big to ignore. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---