Hi,
This example --
http://blog.hasmanythrough.com/2006/03/01/association-goodness-2
-- shows how to pass a parameter to an extended association; Ie: books
josh.books.by_role("author")
Is there ANY way to do this with a dynamic variable in combination with
active eager loading? Ie: This works: "p.fgp.by_fg(9)", but this does
not: "p = Proposal.find(317, :include => :fgp.by_fg(9))", giving
"NoMethodError: undefined method `by_fg'' for :fgp:Symbol"
when used with
:include/eager loading.
All I''m after is having AR''s eager loading joins contrain the
joined
tables at the join rather than the where clause. Ie: "LEFT OUTTER JOIN
fgp ON ... **AND fgp.id_fg = 9**"
I can''t find any way to accomplish this outside find_by_sql or :joins,
and I''d very much like to retain the resulting object composition AR
gives when using :include.
Thanks and best to everyone. Rails is great!
Cheers!
--
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
-~----------~----~----~----~------~----~------~--~---
Webmanager
2007-Feb-10 07:07 UTC
Re: Extending/Constraining Associations when Eager Loading?
To respond to my own post, this bit from the docs on eager loading likely details the root of the issue (no?): "When eager loaded, conditions are interpolated in the context of the model class, not the model instance. Conditions are lazily interpolated before the actual model exists." (http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html) Cheers.> Hi, > > This example -- > http://blog.hasmanythrough.com/2006/03/01/association-goodness-2 > -- shows how to pass a parameter to an extended association; Ie: books > josh.books.by_role("author") > > Is there ANY way to do this with a dynamic variable in combination with > active eager loading? Ie: This works: "p.fgp.by_fg(9)", but this does > not: "p = Proposal.find(317, :include => :fgp.by_fg(9))", giving > "NoMethodError: undefined method `by_fg'' for :fgp:Symbol" when used with > :include/eager loading. > > All I''m after is having AR''s eager loading joins contrain the joined > tables at the join rather than the where clause. Ie: "LEFT OUTTER JOIN > fgp ON ... **AND fgp.id_fg = 9**" > > I can''t find any way to accomplish this outside find_by_sql or :joins, > and I''d very much like to retain the resulting object composition AR > gives when using :include. > > Thanks and best to everyone. Rails is great! > > Cheers!-- 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 -~----------~----~----~----~------~----~------~--~---