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?