Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 722
Magnus Avatar asked May 26 '26 04:05

Magnus


1 Answers

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

Do this

Model.scoped.to_sql
like image 149
egze Avatar answered May 28 '26 19:05

egze