Gabe da Silveira wrote: > He means there's no way to do custom eager loading. Namely, a > find_by_sql (or any find call without :include for that matter) only > ever instantiates models of a single type. There is a much larger class > of performance problems that can be solved by allowing instantiation of > arbitrary models out of any given query (ie. model graphs based on > dev-supplied JOINs). > > Personally I believe this should be possible not only with find_by_sql, > but also find + :joins/:select, since that allows the developer to > continue leveraging the power of AR query generation which I rely upon > heavily in my current project. > > I'm working on a solution to this, but I have quite a few deadlines to > get through before I can devote serious energy to it. The hard part is > figuring out what the interface should look like.
Gabe, are you talking about eager-loading finds having custom joins that don't just load along a chain but match-up arbitrary foreign keys? I and others have written patches for find_by_sql/:finder_sql that allows them to accept an :include option, instantiating the object hierarchy from SQL that uses field aliasing of the Rails eager loading form: http://www.kellogg-assoc.com/articles/2006/11/05/eager-finder-sql http://mrj.bpa.nu/eager_custom_sql_rails_1.2.rb Or are you talking about having eager-loading instantiate the cross and back links of the object hierarchy? A patch that implemented the first step of this -- matching and caching not just the instances seen in each eager-loaded association, but those in each model class -- was posted here several weeks ago by Fred Cheung. A simple eager-loaded object tree is the most common query required in a Web app, and being able to restrict the attributes selected can make a huge speed and space difference when unwanted fields are large and the eager load runs deep. -- 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: Core" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
