There is getSelect()->__toString();
is available in Magento 1 for print query of collection. like below example
$products = Mage::getModel(‘catalog/product’)
->addAttributeToFilter(‘status’, array(‘eq’ => 1));
echo $products->getSelect()->__toString();
Is there any method available in Magento 2?
I have found this ->printLogQuery(true);
but doesn't work for me.
Update: below is the code. I am trying to get the best seller products. It works perfect but I want to print a query for debugging.
$this->_collection->getSelect()
->joinLeft(
'sales_order_item',
'e.entity_id = sales_order_item.product_id',
array('qty_ordered'=>'SUM(sales_order_item.qty_ordered)'))
->group('e.entity_id')
->order('qty_ordered '.$this->getCurrentDirectionReverse());
printLogQuery
with