Mark James
2006-Mar-18 05:48 UTC
Eager loading for both find_by_sql and associations using custom finder_sql
Hi, Only a couple of lines of code needed to be changed in order to get eager loading (:include option) working with a has_many association that uses a custom finder_sql. A similarly small change would be needed to also make eager loading work with find_by_sql. I''d like some feedback on whether it''d be worthwhile to make available a patch that implements both of these. I for one found such a capability useful, however the custom sql must use eager loading''s tn_rn aliasing, correctly matching attribute names and aliases. This is tricky to implement, maintain, and document. Mark
Tom Ward
2006-Mar-18 17:19 UTC
Re: Eager loading for both find_by_sql and associations using custom finder_sql
On 3/18/06, Mark James <mrj@bigpond.net.au> wrote:> Hi, > > Only a couple of lines of code needed to be changed in order to get > eager loading (:include option) working with a has_many association > that uses a custom finder_sql. A similarly small change would be > needed to also make eager loading work with find_by_sql. > > I'd like some feedback on whether it'd be worthwhile to make available > a patch that implements both of these. I for one found such a capability > useful, however the custom sql must use eager loading's tn_rn aliasing, > correctly matching attribute names and aliases. This is tricky to > implement, maintain, and document.Is there any way you can implement your changes as a plugin, or are they too deeply imbedded into ActiveRecord? In either case, it's worth releasing your code one way or another, as someone will surely find it useful, even if it never makes into the main core. Tom _______________________________________________ Rails-core mailing list Rails-core@lists.rubyonrails.org http://lists.rubyonrails.org/mailman/listinfo/rails-core
Mark James
2006-Mar-19 12:26 UTC
Re: Eager loading for both find_by_sql and associations using custom finder_sql
Tom Ward wrote:> Is there any way you can implement your changes as a plugin, or are > they too deeply imbedded into ActiveRecord? In either case, it''s > worth releasing your code one way or another, as someone will surely > find it useful, even if it never makes into the main core.Tom, a plugin''s a good idea because the changes to AR are pretty small. Here''s the code in a file that can be put in an app''s lib directory and require-ed in environment.rb: http://mrj.bpa.nu/eager_custom_sql.rb I haven''t yet worked out how to turn this into a working plugin. Mark