How do you sort results by the stat column

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!

Any thoughts on this anyone?

This is not supported (anything related with aggregation is not the strength of AR). You may consider using JOIN and findAllBySql()