请问relation关系里配置

比如文章列表页面,我要实时统计每条记录的评论数,下面配置要怎么改才行,现在总是报错

CDbCommand failed to execute the SQL statement: SQLSTATE[HY000]: General error: 1140 Mixing of GROUP columns (MIN(),MAX(),COUNT(),…) with no GROUP columns is illegal if there is no GROUP BY clause

我的relation配置

public function relations()

{

return array(


	'Comments' => array(self::HAS_MANY  , 'Comments' , 'ART_ID', 'select'=>'COUNT(COMMENT_ID) AS TOTALS'),	


);

}

这是SQL的规定,你如果用了COUNT, MIN之类的函数,那么出现在select里的其他列也必须列在GROUP BY上。

针对这种需求,我最近加了个新功能(你需要用最新的SVN版本):



public function relations()


{


   return array(


      'commentCount' => array(self::STAT, 'Comments' , 'ART_ID'), 


   );


}


通过访问$post->commentCount就可以获得comment数了。

哦,谢谢.但是我是用的1.0.1,升级的话好像relation配置那里要改不少.

请问在1.0.1里有没有什么办法呢?

如果不想升级的话,这类问题最好直接用SQL来解决。