From this example: (see: http://www.yiiframework.com/doc/api/CActiveRecord)
class Post extends CActiveRecord
{
......
public function relations()
{
return array(
'commentCount'=>array(self::STAT,'Comment','postID'),
'comments'=>array(self::HAS_MANY,'Comment','postID',
'order'=>'??.createTime DESC',
'with'=>'author'),
);
}
}
Which returns the number of comments for a given post ($post->commentCount)
How do you then order the posts based on the comment count? using csort?
i.e. Posts::model->findALL(‘order by comment count’) <- insert real solution here!