sort relation model count yii2 code example
Example: sort relation model count yii2
$query = Folder::find()->joinWith(['documents'])->orderBy(['COUNT(documents.id)' => SORT_ASC])->groupBy('folder.id');
$query = Folder::find()->joinWith(['documents'])->orderBy(['COUNT(documents.id)' => SORT_ASC])->groupBy('folder.id');