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

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

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

#1 User is offline   riyazMuhammed 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 43
  • Joined: 13-September 12
  • Location:Bangalore

Posted 10 January 2013 - 03:07 AM

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() ???
0

#2 User is offline   Ehtesham 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 07-December 11

Posted 18 March 2013 - 04:57 AM

BUMP
I am having the same exact issue :mellow:
@riyazMuhammed, were you able to find the fix or reason?
0

#3 User is offline   riyazMuhammed 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 43
  • Joined: 13-September 12
  • Location:Bangalore

Posted 18 March 2013 - 06:42 AM

View PostEhtesham, on 18 March 2013 - 04:57 AM, said:

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);

0

#4 User is offline   jacmoe 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 2,601
  • Joined: 10-October 10
  • Location:Denmark

Posted 18 March 2013 - 08:10 AM

/* moved from Bug Discussions */
"Less noise - more signal"
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users