Find Out The SQL Query That Was Used To Retrieve A Collection

Posted on August 4, 2011 by admin There have been 0 comments

To find out the SQL query Magento uses to retrieve a specific collection, just do the following:

Let's say you would like to know what query is used to get a product collection - go to your debugging area (or maybe some phtml file), and paste following code:

 

$_productCollection = Mage::getResourceModel("catalog/product_collection");
$_productCollection->load(true);

 

Passing "true" as a parameter to the load function, will print out the query that Magento uses to retrieve the items for the collection.


This post was posted in Working With Magento Collections and was tagged with Magento collections, debugging

Comments
Magento is a well-engineered eCommerce platform designed to help engineers develop customized eCommerce online stores. Due to lack of proper coding documentation, Engineer-ing.com was created with the sole purpose of instructing Magento developers to-be with the "how-to-do" know-how. In the event of unresolved issues, you are more than welcome to contact me for consultation. However, please do so only if you possess a Software Engineering background and you're able to specify your question.