CListView得排序只能根据当前表字段排序?

我有一个post表,一个comment表,我想用CListView显示得时候,能根据回复数排序,也就是comment得数量

post:文章列表

comment:文章评论列表

一个post可以有多个comment

我给post得model-Post自己写了一个属性,public $commentCount, dataProvider得sort属性指定attributes,可是这样做不行,说找不到commentCount,哪位给我指点一下,应该从哪下手?多谢了!

问题解决了:

$criteria->select = ‘t.*, IFNULL(count(fq_conflict_comment.id), 0) as commentCount’;

$criteria->join = 'LEFT JOIN fq_conflict_comment on fq_conflict_comment.conflict_id=t.id';


$criteria->group  = 't.id';





$sort = new CSort('Conflict');


$sort->attributes = array(


  'commentCount'  => array(


    'asc' => 'commentCount',


    'desc' => 'commentCount desc',


    'label' => '评论数',


  ),


  '*',


);

学习了! :rolleyes:

:rolleyes:

过路!

CListView 每一条记录 require 一次,这样会不会有点慢啊