How to Get Final SQL Query from Grid Including Filters

debugginggridsql

I'm trying to get the raw sql query Magento is running on the database to select the data for the report grid. I can print the collection query string with

$collection->getSelect()->__toString()

but this does not contain the filters. But I need the query with filters.
Thanks for any help

Best Answer

$collection->load();
$collection->getSelect()->__toString()

Should work. If you are using an EAV collection you have the problem, that the first query (the one you see) only loads IDs which applied the filters and afterwards loads the attributes (you don't see this query).

With @Phil's answer you see everything, which might be a little bit confusing but complete :-)

Related Topic