简体   繁体   English

ActiveRecord在Rails 3中生成SQL

[英]ActiveRecord generated SQL in Rails 3

I'm working on a project which requires talking to two different databases: a MySQL one for persistent data and an experimental in-memory database for real-time data. 我正在开发一个项目,需要与两个不同的数据库交谈:一个用于持久数据的MySQL和一个用于实时数据的实验性内存数据库。

It would make my life a bit easier if there was a way to access and use the SQL Query generated by the ActiveRecord finders. 如果有办法访问和使用ActiveRecord查找程序生成的SQL查询,这将使我的生活更轻松。


I know there have been other questions along these lines but the answers they had seemed to suggest logging the SQL to STDOUT and were not for Rails 3 我知道在这些方面还有其他问题,但他们的答案似乎建议将SQL记录到STDOUT而不是Rails 3

Model.all executes the query and you are trying to call to_sql on an Array. Model.all执行查询,您尝试在Array上调用to_sql

Do this 做这个

Model.scoped.to_sql

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM