public function run() { $categories = Category::find()->joinWith(['posts'])->addSelect(['category.*', 'count(post.id) as postCount'])->groupBy('category.id')->all(); echo $this->renderCategories($categories, null, 0); }