1.1.4
Привожу пример кода, структуру таблиц и описание ошибки.
Как вызвать ошибку
Код контроллера:
Код: Выделить всё
$dataProvider=new CActiveDataProvider('SupportMessage',array(
'criteria'=>array(
'select'=>'*,max(date) as date',
'condition'=>'`type`="ask" and idUser=:user',
'params'=>array(
':user'=>Yii::app()->user->Id,
),
'group'=>'idTheme',
'with'=>'theme'
),
'pagination'=>array(
'pageSize'=>5
)
));
$this->render('index',array(
'dataProvider'=>$dataProvider
));
Код: Выделить всё
<?php $this->widget('zii.widgets.grid.CGridView', array(
'dataProvider'=>$dataProvider,
));?>
Код: Выделить всё
<?php
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
* Description of SupportMessage
*
* @author root
*/
class SupportMessage extends CActiveRecord
{
public static function model($className = __CLASS__)
{
return parent::model($className);
}
public function relations()
{
return array(
'theme'=>array(self::BELONGS_TO,'SupportTheme','idTheme'),
);
}
//put your code here
}
Код: Выделить всё
<?php
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
* Description of SupportTheme
*
* @author root
*/
class SupportTheme extends CActiveRecord
{
public static function model($className=__CLASS__)
{
return parent::model($className);
}
//put your code here
}
Суть проблемы в том, что при подсчете числа записей в формируемом sql запросе не используетя группировка. Формируются следующие запросы:
Запрос на выборку:
2010/11/24 00:36:31 [trace] [system.db.CDbCommand] Querying SQL: SELECT `t`.`Id` AS `t0_c0`, `t`.`idUser` AS `t0_c1`, `t`.`idTheme` AS `t0_c2`, `t`.`date` AS `t0_c3`, `t`.`message` AS `t0_c4`, `t`.`file` AS `t0_c5`, `t`.`type` AS `t0_c6`, max(date) as date, `t`.`Id` AS `t0_c0`, `theme`.`Id` AS `t1_c0`, `theme`.`idTopic` AS `t1_c1`, `theme`.`theme` AS `t1_c2`, `theme`.`name` AS `t1_c3`, `theme`.`responseToEmail` AS `t1_c4`, `theme`.`responseToPhone` AS `t1_c5`, `theme`.`responsed` AS `t1_c6`, `theme`.`viewed` AS `t1_c7` FROM `SupportMessage` `t` LEFT OUTER JOIN `SupportTheme` `theme` ON (`t`.`idTheme`=`theme`.`Id`) WHERE (`type`="ask" and idUser=:user) GROUP BY idTheme LIMIT 5. Bind with parameter :user='20'
Запрос на подсчет числа записей:
2010/11/24 00:36:31 [trace] [system.db.CDbCommand] Querying SQL: SELECT COUNT(DISTINCT `t`.`Id`) FROM `SupportMessage` `t` LEFT OUTER JOIN `SupportTheme` `theme` ON (`t`.`idTheme`=`theme`.`Id`) WHERE (`type`="ask" and idUser=:user). Bind with parameter :user='20'
Проблема возникает в классе CJoinElement при формировании count запроса:
Строка 625, CActiveFinder.php
Код: Выделить всё
$query->orders=$query->groups=$query->havings=array();