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?
我想检查一下ActiveRecord生成的一些查询,但我不需要实际运行它们。有没有办法在返回结果之前获取查询?
4 个解决方案
#1
5
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/8/watching-activerecord-do-it-s-thing
http://weblog.jamisbuck.org/2007/1/31/more-on-watching-activerecord
http://weblog.jamisbuck.org/2007/1/31/more-on-watching-activerecord
#2
2
i think it's buried in:
我认为它被埋没在:
construct_finder_sql,
http://groups.google.com/group/rubyonrails-talk/browse_frm/thread/38c492e3939dd9bf/?pli=1
http://groups.google.com/group/rubyonrails-talk/browse_frm/thread/38c492e3939dd9bf/?pli=1
#3
2
tail -f log/development.log
tail -f log / development.log
Works in default settings or when you set your logger level to DEBUG.
在默认设置或将记录器级别设置为DEBUG时工作。
#4
0
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:
Jamis的文章已经过时,或者至少不适用于我的Rails应用程序(可能是由于其他原因,使用3岁的30,000行应用程序)。但是,这可以在控制台中随时使用:
ActiveRecord::Base.connection.instance_variable_set :@logger, Logger.new(STDOUT)
#1
5
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/8/watching-activerecord-do-it-s-thing
http://weblog.jamisbuck.org/2007/1/31/more-on-watching-activerecord
http://weblog.jamisbuck.org/2007/1/31/more-on-watching-activerecord
#2
2
i think it's buried in:
我认为它被埋没在:
construct_finder_sql,
http://groups.google.com/group/rubyonrails-talk/browse_frm/thread/38c492e3939dd9bf/?pli=1
http://groups.google.com/group/rubyonrails-talk/browse_frm/thread/38c492e3939dd9bf/?pli=1
#3
2
tail -f log/development.log
tail -f log / development.log
Works in default settings or when you set your logger level to DEBUG.
在默认设置或将记录器级别设置为DEBUG时工作。
#4
0
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:
Jamis的文章已经过时,或者至少不适用于我的Rails应用程序(可能是由于其他原因,使用3岁的30,000行应用程序)。但是,这可以在控制台中随时使用:
ActiveRecord::Base.connection.instance_variable_set :@logger, Logger.new(STDOUT)