views:

284

answers:

4

I'd like to check a few queries generated by ActiveRecord, but I don't need to actually run them. Is there a way to get at the query before it returns its result?

+5  A: 

Both of these articles should help you do what you want.

http://weblog.jamisbuck.org/2007/1/8/watching-activerecord-do-it-s-thing

http://weblog.jamisbuck.org/2007/1/31/more-on-watching-activerecord

jonnii
Those still run the queries, but they solve the problem I was really after, since the queries (a) are idempotent and (b) don't take too long.
James A. Rosen
+2  A: 

i think it's buried in:

construct_finder_sql,

http://groups.google.com/group/rubyonrails-talk/browse_frm/thread/38c492e3939dd9bf/?pli=1

Gene T
+2  A: 

tail -f log/development.log

Works in default settings or when you set your logger level to DEBUG.

Honza
A: 

Jamis' article is outdated, or at least doesn't work my Rails app (possibly due to some other reason with a 3 year old 30,000 line app). However this works in a console any time:

ActiveRecord::Base.connection.instance_variable_set :@logger, Logger.new(STDOUT)
dasil003