如何显示在Rails控制台中运行SQL查询? [英] How to show SQL queries run in the Rails console?
本文介绍了如何显示在Rails控制台中运行SQL查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我运行的查询(如 MyModel.where(...)
或 record.associated_things
)的控制台,我怎么能看到正在运行的实际数据库查询,以便我能获得对正在发生的事情比较了解?
When I run queries (e.g. MyModel.where(...)
or record.associated_things
) in the console, how can I see the actual database queries being run so I can gain more understanding of what is happening?
推荐答案
在控制台上输入这行:
ActiveRecord::Base.logger = Logger.new(STDOUT)
这篇关于如何显示在Rails控制台中运行SQL查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文