Hi, I tried using the eager_custom_sql.rb fix to be able to eager load associations using find_by_sql. I was able to get this working for my has_many associations, however, Im having trouble getting it to work for belongs_to associations. Has anyone experienced this? Any fixes? -- 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
2007-Apr-16 13:55 UTC
Re: eager loading associations fix belongs_to doesn''t work
Aryk Grosz wrote:> I tried using the eager_custom_sql.rb fix to be able to eager load > associations using find_by_sql. > > I was able to get this working for my has_many associations, however, Im > having trouble getting it to work for belongs_to associations. > > Has anyone experienced this? Any fixes?belongs_to doesn''t support a :finder_sql option, so you can''t use fully-custom sql. I''d be interested to see a belongs_to that actually requires it. -- 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 -~----------~----~----~----~------~----~------~--~---
Aryk Grosz
2007-Apr-16 16:51 UTC
Re: eager loading associations fix belongs_to doesn''t work
Hmm, so if you want to use manual sql, how can you return a belongs_to object alongside the main object or do you just have to use the standard "find" with the "include" option? -- 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
2007-Apr-17 13:47 UTC
Re: eager loading associations fix belongs_to doesn''t work
Aryk Grosz wrote:> Hmm, so if you want to use manual sql, how can you return a belongs_to > object alongside the main object or do you just have to use the standard > "find" with the "include" option?Oh, you mean the belongs_to is the association you want eager loaded, not that you want to use the :include method in the declaration of a belongs_to, eager loading its descendants? If so, find_by_sql and the :include option should work if you''ve correctly written all the custom sql joins and field aliasing. -- 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 -~----------~----~----~----~------~----~------~--~---
Aryk Grosz
2007-Apr-17 20:46 UTC
Re: eager loading associations fix belongs_to doesn''t work
Yeah, this is what Im attempting to do. I have the eager_custom_sql.rb fix. In the patch, they write: # This Active Record mod enables eager loading of associations # (the :include option) for both the find_by_sql method and has_many # and has_and_belongs_to_many associations that use the :finder_sql option. So they don''t include the "belongs_to" case. Nevertheless, I tried formatting it as you said and I got it working with the "has_many" relationships, but not with my belongs_to assocations. Anyone had any success getting find_by_sql working with including a belongs_to association? Mark Reginald James wrote:> Aryk Grosz wrote: >> Hmm, so if you want to use manual sql, how can you return a belongs_to >> object alongside the main object or do you just have to use the standard >> "find" with the "include" option? > > Oh, you mean the belongs_to is the association you want eager loaded, > not that you want to use the :include method in the declaration > of a belongs_to, eager loading its descendants? > > If so, find_by_sql and the :include option should work if you''ve > correctly written all the custom sql joins and field aliasing. > > -- > We develop, watch us RoR, in numbers too big to ignore.-- 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 -~----------~----~----~----~------~----~------~--~---