On Jul 9, 2010, at 6:57 PM, Rodrigo Rosenfeld Rosas wrote: > > Is it difficult to add some method to ActiveRecord that displays exactly the > SQL that will be run, or that would be run if eager loading was set? I mean, > maybe some methods like "eager_sql" and "lazy_sql"? I don't know > ActiveRecord's code, but I guess that sometime it will need to generate the > full sql string, so the method should be already there... Is there any > reasons why we can't just see the full sql statement without actually running > the query? Sometimes it would even easy some test/spec writing or even make > some of them to run faster...
I don't think it would be terribly difficult, no -- it'd basically be doing arel.to_sql or a partial version of find_with_associations depending on the result of eager_loading? that looks something like this and sticking it in relation.rb (not tested): def real_sql if eager_loading? including = (@eager_load_values + @includes_values).uniq join_dependency = ActiveRecord::Associations::ClassMethods::JoinDependency.new(@klass, including, nil) construct_relation_for_association_find(join_dependency).to_sql else arel.to_sql end end I think it's just been a matter of there not being a real use case requiring it to be in core. I could throw it into MetaWhere easily enough if enough people thought it'd be useful though. I'm trying to position it as a sort of "AR Query Interface 3.0 on steroids" anyway. -Ernie -- 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 rubyonrails-c...@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.