Can anyone explain to me the sql query done in the last step : http://pastie.org/402200 -- Arpit Jain --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
It has nothing to do with polymorphism. You''ll want to look into eager loading for your associations if you want to avoid those queries. http://railscasts.com/episodes/22 -e On Feb 27, 9:58 am, Arpit Jain <arpitjai...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Can anyone explain to me the sql query done in the last step : > > http://pastie.org/402200 > > -- > Arpit Jain--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2009-Feb-27 23:45 UTC
Re: Polymorphic association..explain the extra query ?
On Feb 27, 5:58 pm, Arpit Jain <arpitjai...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Can anyone explain to me the sql query done in the last step : > > http://pastie.org/402200 >Because activerecord isn''t super smart in this way and doesn''t fill in associations bidirectionally when they are loaded. Fred> -- > Arpit Jain--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
So what''s the solution to that Fred ? I would have to load question also when I load the subquestion ? That would mean doing a different query twice for extracting the same object. Or is there any other way around ? On Sat, Feb 28, 2009 at 5:15 AM, Frederick Cheung < frederick.cheung-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > > On Feb 27, 5:58 pm, Arpit Jain <arpitjai...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > Can anyone explain to me the sql query done in the last step : > > > > http://pastie.org/402200 > > > > Because activerecord isn''t super smart in this way and doesn''t fill in > associations bidirectionally when they are loaded. > > Fred > > > > -- > > Arpit Jain > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2009-Feb-28 11:57 UTC
Re: Polymorphic association..explain the extra query ?
On Feb 28, 1:57 am, Arpit Jain <arpitjai...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> So what''s the solution to that Fred ? I would have to load question also > when I load the subquestion ? That would mean doing a different query twice > for extracting the same object. Or is there any other way around ? >There isn''t really good solution. There''s a plugin that attempts to address this (parental_control), or you can fiddle around making ar believe it has already loaded it. The ar_context plugin can also be helpful in this context. You can also make your include load it (ie :include => {:subquestion => :question} but that always seems a bit messy. You also do things semi manually ie instead of referencing foo.question, collect all the questions into a hash indexed by id and access your_hash[foo.question_id] Fred> On Sat, Feb 28, 2009 at 5:15 AM, Frederick Cheung < > > frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > On Feb 27, 5:58 pm, Arpit Jain <arpitjai...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Can anyone explain to me the sql query done in the last step : > > > >http://pastie.org/402200 > > > Because activerecord isn''t super smart in this way and doesn''t fill in > > associations bidirectionally when they are loaded. > > > Fred > > > > -- > > > Arpit Jain--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
hmm Right.. Thanks :) On Sat, Feb 28, 2009 at 5:27 PM, Frederick Cheung < frederick.cheung-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > > On Feb 28, 1:57 am, Arpit Jain <arpitjai...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > So what''s the solution to that Fred ? I would have to load question also > > when I load the subquestion ? That would mean doing a different query > twice > > for extracting the same object. Or is there any other way around ? > > > There isn''t really good solution. There''s a plugin that attempts to > address this (parental_control), or you can fiddle around making ar > believe it has already loaded it. The ar_context plugin can also be > helpful in this context. > You can also make your include load it (ie :include => {:subquestion > => :question} but that always seems a bit messy. > You also do things semi manually ie instead of referencing > foo.question, collect all the questions into a hash indexed by id and > access your_hash[foo.question_id] > > Fred > > On Sat, Feb 28, 2009 at 5:15 AM, Frederick Cheung < > > > > frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > On Feb 27, 5:58 pm, Arpit Jain <arpitjai...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > Can anyone explain to me the sql query done in the last step : > > > > > >http://pastie.org/402200 > > > > > Because activerecord isn''t super smart in this way and doesn''t fill in > > > associations bidirectionally when they are loaded. > > > > > Fred > > > > > > -- > > > > Arpit Jain > > >-- Arpit Jain --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---