select(['id', 'name']) ->all(); } public function actionWithProducts() { return Category::find() ->select(['id', 'name']) ->with([ 'products' => function (\yii\db\ActiveQuery $query) { $query->select(['name', 'description', 'price', 'category_id']); } ]) ->asArray() ->all(); } }