简体   繁体   中英

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.

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.


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

Model.all executes the query and you are trying to call to_sql on an Array.

Do this

Model.scoped.to_sql

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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