Проблема только в том, что несмотря на то что я указываю
Код: Выделить всё
$criteria->select = array("SUM(price) as price");
В результирующем запросе присутствует не только SUM(price) as price, но и поля из реляций
Код: Выделить всё
SELECT SUM(price) as price, `t`.`id` AS `t0_c0`, `customer`.`id` AS `t1_c0`...
поэтому вываливается ошибка GROUP BY. Если бы там осталось только SUM(price) - все было бы отлично.
Вот кусок кода:
Код: Выделить всё
public function search( $export = false , $totals = false )
{
$criteria = new CDbCriteria;
$criteria->compare('product.category',$this->category);
...
$criteria->compare( 'industries_c2i.industry_id' , $this->industry_id );
if( $this->industry_id || $this->category ){
$criteria->with = array('customer.industries','product');
$criteria->together = true;
}
if( $totals )
{
$criteria->select = array("SUM(price) as price");
$result = self::model()->find( $criteria );
return $result->price;
}
return new CActiveDataProvider(get_class($this), array(
'criteria' => $criteria,
'sort' => array( 'defaultOrder' => 't.id desc' ),
'pagination' => $export ? false : null ,
));
}
Я использую одну и ту же функцию в гриде, для экспорта и для получения суммы.
В случае если $totals = true; наблюдаю описанную ситуацию.
Если $this->industry_id || $this->category не установлены все отрабатывает отлично, но если подключаются реляции получаю ошибку.