Cdbcriteria With "select" Selecting Wrong Column In Case Of Model->Count()

Hi guys,

I found this issue while working on my project.

when I have this piece of code :




$criteria = new CDbCriteria;

           $criteria->condition='

           TrainingPlanDeliveryID IN

            (select TrainingplanDeliveryID from trainingplandeliverydetails where TrainingPlanID = '.$this->TrainingPlanID.')    

           ';

            $criteria->select = array('UserID');

            $criteria->distinct = true;

           $totalIdeliveredthisplan = Trainingplandeliverydetailsforusers::model()->findAll($criteria);



This is exactly selecting only userID from result.

But here i wanted to count the result, so I modified model()->findAll to model()->count as:




$criteria = new CDbCriteria;

           $criteria->condition='

           TrainingPlanDeliveryID IN

            (select TrainingplanDeliveryID from trainingplandeliverydetails where TrainingPlanIDs = '.$this->TrainingPlanID.')    

           ';

            $criteria->select = array('UserID');

            $criteria->distinct = true;

           $totalIdeliveredthisplan = Trainingplandeliverydetailsforusers::model()->count($criteria);



Now I noticed that , this query is selecting "UserdeliveryID" which is the primary key of this table.

Anyways I could get the count by


sizeof($totalIdeliveredthisplan)

with findAll(),But i want to know why is this happening wrong when I use count() ???

BUMP

I am having the same exact issue :mellow:

@riyazMuhammed, were you able to find the fix or reason?

No Buddy :(

You can do as follows to achieve it for now!

You can use the following to query:




$criteria = new CDbCriteria;

           $criteria->condition='

           TrainingPlanDeliveryID IN

            (select TrainingplanDeliveryID from trainingplandeliverydetails where TrainingPlanID = '.$this->TrainingPlanID.')    

           ';

            $criteria->select = array('UserID');

            $criteria->distinct = true;

           $totalIdeliveredthisplan = Trainingplandeliverydetailsforusers::model()->findAll($criteria);




and the following to find the count




$countVar=sizeof($totalIdeliveredthisplan);



[color="#006400"]/* moved from Bug Discussions */[/color]