S
S
Sergey Beloventsev2016-05-16 19:59:24
Yii
Sergey Beloventsev, 2016-05-16 19:59:24

Why doesn't Count(*) as work?

This is how I write

$top=Watch::find()
                ->select(['fl_serial.*,fl_watch.*,COUNT(fl_watch.active=1) AS total_count'])
                ->joinWith('serial','fl_watch.id_serial=serial.id')
                ->groupBy('fl_watch.id_serial')
                ->orderBy(['total_count'=>SORT_DESC])
                ->limit(10)
                ->all();

then process like this
foreach($top as $post){
     $posts[]=$post->total_count;}

I get `Getting unknown property: common\models\Watch::total_count` how to properly process `COUNT( * ) AS total_count`

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Fedorov, 2016-05-16
@qonand

Apparently, there is no total_count property in the Watch model, so it needs to be added:
public $total_count;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question