针对这种需求,我最近加了个新功能(你需要用最新的SVN版本):
Code:
[Select]
public function relations()
{
return array(
'commentCount' => array(self::STAT, 'Comments' , 'ART_ID'),
);
}
通过访问$post->commentCount就可以获得comment数了。
比如文章列表页面,我要实时统计每条记录的评论数,下面配置要怎么改才行,现在总是报错
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'),
);
}
public function relations()
{
return array(
'commentCount' => array(self::STAT, 'Comments' , 'ART_ID'),
);
}