I can get the base query for a given grid view by calling var_dump in Mymodule_Block_Adminhtml_Myaction_Grid

protected function _prepareCollection() {
    return parent::_prepareCollection();

...but this returns a "base" query before any pagination or filters are applied in creating the grid view. I'd like to be able to examine the query that is actually used to generate a specific grid view. Reason being is that while executing this base query in MySQL returns results I'd expect, the grid view in Magento does not, and I'd like to see what's actually in use.

Any ideas?

1 Answer 1


You can run getSelect on collection at any given moment. Display it immediately BEFORE the pagination is displayed (in .phtml file). Don't forget that many functions use objects as reference and even though it looks its just a parameter those functions actually update the collection that gets passed to them.

  • 1
    Adding var_dump($this->getCollection()->getSelect()->__toString()); to app/design/default/default/template/widget/grid.phtml was just what I was looking for. Thanks. Commented Jun 30, 2014 at 16:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.