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,
I would love some help understanding any of this.
September 19, 2010, 8:40pm
I also think that something broke with latest patch…
September 20, 2010, 1:16pm
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:
Here are the bug signalation:
September 20, 2010, 1:20pm
Here the file for workaround
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.