What's the code to look at the sql an ActiveRecord query is going to produce. For example, Modelname.all would produce "Select * from modelname". Is there any method that gives access to that string?
+1
A:
I don't know if it can be done through an API, but you can see the generated SQL by looking at development.log, which I suppose you could parse.
Extending this answer, you can provide a custom Logger to ActiveRecord via
ActiveRecord::Base.logger = yourLoggerHere
Maybe you can create a Logger that'll do all the work for you. Found this link which implements one for detecting slow queries.
JRL
2010-02-06 15:42:56
Thanks JRL, I'm actually looking specifically for how its done throug the API.
Daniel
2010-02-06 15:58:35
A:
There's no API method to store the queries executed by ActiveRecord. However, you can hack ActiveRecord, as explained here.
Simone Carletti
2010-02-06 19:45:44