Not sure if this is intended behaviour.
But an “ORDER BY” should be removed with the model’s COUNT() call.
Why is it needed?
I am ordering a result set based on a custom field in my select statement.
Running a count() triggers an error. A simple example below.
// to trigger the error
$c = new CDbCriteria;
$c->select = array('id','name as customFieldName');
$c->order = 'customFieldName ASC';
SomeModel::model()->count($c);
I’m fixing this by altering CDbCommandBuilder::createCountCommand
// FROM
$this->ensureTable($table);
$criteria->select='COUNT(*)';
return $this->createFindCommand($table,$criteria);
// TO
$this->ensureTable($table);
$c = clone $criteria;
$c->order = '';
$c->select = 'COUNT(*)';
return $this->createFindCommand($table, $c);
thoughts? should i post a bug?