Magento constructs its SQL queries like
$this->getSelect()->joinInner(
array('sbao' => $this->getTable('sales/billing_agreement_order')),
'main_table.entity_id = sbao.order_id',
array()
)
Is there a way to display the resulting query in a string format rather than printing out the huge object e.g.
echo $this->getSelect()->joinInner(
array('sbao' => $this->getTable('sales/billing_agreement_order')),
'main_table.entity_id = sbao.order_id',
array()
)->toString();
Note: You can use literal string (enclosed in single or double quotation mark) just like we use a column name in the SELECT statement. If you use the literal string with a column then it will be displayed in every row of the query results.
Save this question. Show activity on this post. $products = Mage::getModel('catalog/product') ->addAttributeToFilter('status', array('eq' => 1)); echo $products->getSelect()->__toString();
When Magento builds a product collection, it layers the filters in one at a time so the full query is not assembled until time of collection load. You might want to do the following to force the collection to load and then print the query: $collection->getItems(); echo $collection->getSelectSql(true);
$select = $this->getSelect()->joinInner(
array('sbao' => $this->getTable('sales/billing_agreement_order')),
'main_table.entity_id = sbao.order_id',
array()
);
echo $select;
I nearly had it for those interested you need to use ->__toString() e.g.
echo $this->getSelect()->joinInner(
array('sbao' => $this->getTable('sales/billing_agreement_order')),
'main_table.entity_id = sbao.order_id',
array()
)->__toString()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With