AR's count method ignores 'select' property of query criteria


This is my criteria definition and the count query:

$criteria = new CDbCriteria;

$criteria->distinct = true;

$criteria->select = 'feedback_employee_id';




			'condition'=>'profile_id = :pId',

			'params' => array(':pId' => $model->profile_id)



$total_employees = FeedbackGrid::model()->count($criteria);

The count method is ignoring the ‘select’ clause of the criteria definition, so the results are different from the expected ones.

Besides, looking at the Yii framework changelog, this bug is suposed to be fixed since this revision:

Link to changelog in googlecode

That was version 1.1.3 (july 2010) and I am using version 1.1.7 (March 2011)

Please any hint on what’s going on here? is that bug fixed then or not?

If not, what would be the best alternative to perform the count operation with ‘select’ and relations?

Thanks in advance!

I’m with the same problem.

Any hint about it?


Anyone? =/

Maybe because the only thing it does it counts the number of rows the SQL expression matches so there is no point is specifying fields because COUNT(*) is what get’s the number in question and the method returns only that number and no other data.

So I’d say it’s intentional. If you need your own version of the query - use DAO

After looking at the createCountCommand() code and assuming that I understand it correctly I would suggest you to try the following

 $criteria->select = 'count(feedback_employee_id)';

cause in the createCountCommand() the select part of the criteria is searched for the word count via stripos.