Take this code for example:
$collection->getSelect()->order(array('status = 1 DESC', 'test ASC'));
Magento/Zend_Db turns this into the following:
ORDER BY `status = 1` DESC, `test` ASC
You can see this with Zend_Debug::dump($collection->getSelect()->__toString());
Notice that it wraps status = 1
with ` characters, as if it were escaping a field? This breaks the query. Is there any way to order by expression in Magento/Zend_Db?
Best Answer
I would think
new Zend_Db_Expr
would do what you need.$collection->getSelect()->order(array(new Zend_Db_Expr('status = 1 DESC'), 'test ASC'))
Details: