Answer the question
In order to leave comments, you need to log in
How to find out which article has the most comments?
How can I find out which article has the most comments?
ArticleController :
$discussedArticle = Articles::find()->with('comments')->groupBy('article_id')->orderBy('count(article_id) DESC')->asArray()->all();
Model : article
public function getComments()
{
return $this->hasMany(Comments::className(), ['article_id' => 'id']);
}
Answer the question
In order to leave comments, you need to log in
Found :D
$discussedArticle = Articles::find()->joinWith('comments', true, 'RIGHT JOIN')->groupBy('comments.article_id')->orderBy('count(comments.article_id) DESC' )->limit(5)->all();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question