[FIXED] AR, with() and group operations

Preference::model()->find(array('select' => 'sum(amount) as amount'));
works fine, but if I use with('something')  SUM(...) is not generated... instead of it generated simple field without SUM(...) group operation

What is the generated SQL?

In the upcoming 1.0.4 release, we added a new relation called STAT. It is mainly used to solve this problem in an easy way.

SELECT `pref`.`amount` AS t0_c6, `pref`.`id` AS t0_c0, log.`id` AS t1_c0 FROM `pref`  LEFT OUTER JOIN `log` log ON `pref`.`logId`=log.`id`

for code:

Preference::model()->with(array(


 'log' => array('select' => 'id')


))->find(array(


 'select' => array('sum(??.amount)' => 'amount'),


))

if I use:

 'select' => 'sum(??.amount) as amount',

amount selector not generated…

Where I can find STAT documentation?  :)

Qiang, maybe you need to change CActiveFinder.php (small bugfix):



					$alias=$matches[2];


					if(!isset($this->_columnAliases[$alias]))


					{


						$this->_columnAliases[$alias]=$alias;


						$columns[]=$name;


						$selected[$alias]=1;


					}

to:



					$alias=$matches[2];


					if(!isset($this->_columnAliases[$alias]) || $this->_columnAliases[$alias]!==$alias)


					{


						$this->_columnAliases[$alias]=$alias;


						$columns[]=$name;


						$selected[$alias]=1;


					}

or to:



					$alias=$matches[2];


					if(!isset($this->_columnAliases[$alias]) || false===in_array($name,$columns,true))


					{


						$this->_columnAliases[$alias]=$alias;


						$columns[]=$name;


						$selected[$alias]=1;


					}

Thanks. Fixed.

For stat, please check http://www.yiiframew…05.html#msg6605