CDbCriteria stopped functioning properly after last update

I just updated to the last version of yii and CDbCriteria seems to malfunction. For example, the following code:


                $criteria = new CDbCriteria ();

		$criteria->select = 't.name, t.id, count(distinct sl.subscriber) as dashboardTotalSubscribes';

		$criteria->distinct = true;

		$criteria->join = 'inner join subscriber_list sl on(sl.list=t.id)';

		$criteria->condition = 'sl.status=:active and sl.date_added>:7days';

		$criteria->order = 'dashboardTotalSubscribes desc';

		$criteria->having = 'dashboardTotalSubscribes>0';

		$criteria->group = 't.name';

		$criteria->limit = 10;

		

		$criteria->params = array ( 

			

			'active' => 'active', 

			'7days' => time () - ( DateHelper::day () * 7 ) 

		);


		return new CActiveDataProvider ( 'Lists', array ( 

			

			'criteria' => $criteria 

		) );

produces the following query:


SELECT COUNT(DISTINCT t.name) FROM `list` `t` inner join subscriber_list sl on(sl.list=t.id) WHERE sl.status=:active and sl.date_added>:7days GROUP BY t.name HAVING dashboardTotalSubscribes>0

And the following error:


CDbCommand failed to execute the SQL statement: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'dashboardTotalSubscribes' in 'having clause'

Can anyone tell me why isn’t the query complete?

I’m also having the same issue,




        $id=$_GET['id'];

        $scrolls=Scrolls::model()->findAll(array(

            'with'=>array(

                'usersScrolls.user.photo'

            ),

            'condition'=>'t.id=:id',

            'params'=>array(':id'=>$id),

            'order'=>'usersScrolls.modified ASC',

            'limit'=>5,

            

        ));



I would love some help understanding any of this.

I also think that something broke with latest patch…

Hi guys.

You are right, there is something broken since long, and since the last patch it trows an exception instead of returning a wrong result.

The staff is working on it, meanwhile you can use my workaround for going over.

Workaround: save the file in the next post in components and add this line to the db config:




db=>array(

     'class'=>'ZDbConnection'



Here are the bug signalation:

http://code.google.com/p/yii/issues/detail?id=1244

http://code.google.com/p/yii/issues/detail?id=675

http://www.yiiframework.com/forum/index.php?/topic/9492-cactiverecord-count-dont-works-with-having/

[error]

Here the file for workaround

Thanks Zaccaria,

I also found another post that talks about how CActiveRecord doesn’t deal with MANY:MANY relationships well and whenever adding a “limit” it breaks. The solution to that is to create a table view. I did that and it works great.