I want to get all IDs from collection using Mage_Core_Model_Resource_Db_Collection_Abstract::getAllIds()
method.
My collection is joined with orders table:
$collection
->getSelect()
->joinLeft(
['o' => $this->getTable('sales/order')], // Table and alias
'main_table.order_id = o.increment_id', // Join condition
[ // Select fields
'store_id' => 'store_id',
'order_created_at' => 'created_at'
]);
But when I want to get all ID's from that collection with a having condition:
$collection->getSelect()->having('order_created_at >= ?', '20-02-2016 0:00:00')
$ids = $collection->getAllIds();
It gives me an error: Unknown column 'order_created_at' in 'having clause'
, because getAllIds()
method resets collections' select columns and there is no way to filter by joined columns:
public function getAllIds()
{
$idsSelect = clone $this->getSelect();
$idsSelect->reset(Zend_Db_Select::ORDER);
$idsSelect->reset(Zend_Db_Select::LIMIT_COUNT);
$idsSelect->reset(Zend_Db_Select::LIMIT_OFFSET);
$idsSelect->reset(Zend_Db_Select::COLUMNS); // Reset columns here
$idsSelect->columns($this->getResource()->getIdFieldName(), 'main_table');
return $this->getConnection()->fetchCol($idsSelect);
}
So how to retreive joined collection ID's?