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 bestseller products. its work perfect but i want to print query for debug.
$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());