Why doesn't leftJoin?

So I write
Watch::find()->select(['fl_serial.*,COUNT(*) AS total_count']) ->leftJoin(['fl_serial',"fl_serial`.`id`=`fl_watch`.`id_serial`])
->where(['fl_watch.active'=>1])->groupBy('fl_watch.id_serial')->orderBy(['total_count'=>SORT_DESC])->limit(10)->all();

get
Syntax error or access violation: 1064 You have an error in your SQL syntaxYou have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE `fl_watch`.`active`=1 GROUP BY `fl_watch`.`id_serial` ORDER BY `total_coun' at line 1
The SQL being executed was: SELECT fl_serial.*,COUNT(*) AS total_count FROM `fl_watch` LEFT JOIN `fl_serial` WHERE `fl_watch`.`active`=1 GROUP BY `fl_watch`.`id_serial` ORDER BY `total_count` DESC LIMIT 10


I do not understand why not fully worked through ->leftJoin(['fl_serial','fl_serial.id=fl_watch.id_serial']) tell me where I went wrong.
July 9th 19 at 13:46
2 answers
July 9th 19 at 13:48
Solution
If You use a framework, use its methods and principles. Create an Association in the model and do it through join.
www.yiiframework.com/doc-2.0/guide-db-active-recor... namely the section "Joining with Relations"
July 9th 19 at 13:50
Solution
The square brackets are redundant here:
leftJoin('fl_serial',"fl_serial`.`id`=`fl_watch`.`id_serial`)


And select() is also unclear:
//select(['fl_serial.*,COUNT(*) AS total_count'])
select('fl_serial.*, COUNT(*) AS total_count')
// or so
select(['fl_serial.*', 'COUNT(*) AS total_count'])

Find more questions by tags Yii