开发者

how to print the executing sql from Active record in rails 2

I would like to print into log or console the executing sql. Where can I make some settings? In hibernate it is in a config file possibility: I think here should be something like that too.

I have a code part similar to this:

myresult = MyActiveRecordClass.find(:all, :select => "mytable1.*, mytable2.field1", 开发者_开发知识库:joins => :mytable2, :conditions => "somefield= #{somefield}", :order => "another_field desc", :offset => offset, :limit => limit)

This is a simpler case to translate by hand, but I would like to have all the native sql in a console or in file. It could be usefully at searching


Rails already displays the SQL in the development log and console (at debug log level - so ensure that the logger is able to display debug log messages).

To also display where in the source code a SQL was called from:

Rails 2: query_trace plugin

Rails 3: Tracing Rails 3 SQL queries (based on query_trace, but works for Rails 3 because query_trace does not currently work on Rails 3)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜