Ordering by relational STAT in yii

I am using yii framework. I have an attitude

'revCount'=>array(self::STAT, 'Review','rid','condition'=>'status=1')//count review for each restaurant


Now I want to get a list of all restaurants by number of views.



What else do I need to add to get all restaurants ordered by reviews?


source to share

2 answers

This is how you join other models with one request:



But I think you want to not join the model, but just sort it. Similar to this:

        // we don't want to select reviews
        // but want to get only reviews with status=1
        'joinType'=>'INNER JOIN',




You should be able to do the following.

Restaurant::model()->findAll('with'=>'revCount', 'select' => '(SELECT COUNT(*) FROM review WHERE rid = t.id AND status = 1) AS revCount');




All Articles