Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion controllers/SiteController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Yii;
use yii\base\Module;
use yii\data\ActiveDataProvider;
use yii\db\ActiveQuery;
use yii\web\Controller;

class SiteController extends Controller
Expand Down Expand Up @@ -56,7 +57,13 @@ public function actionView()
{
return $this->render('view', [
'newsDataProvider' => new ActiveDataProvider([
'query' => News::find()->orderBy('id desc'),
'query' => News::find()
->with(['tags' => function ($query) {
/** @var ActiveQuery $query */
$query->with('news');
}])
// ->with('tags.news') // the same as above
->orderBy('id desc'),
Copy link

@cebe cebe Jun 19, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to reduce the overhead of instantiating the News AR instances for tags the following asArray() call can be added:

      'query' => News::find()->with(['tags' => function($q) {
          /** @var ActiveQuery $q */
          $q->with(['news' => function($q) {
              /** @var ActiveQuery $q */
              $q->asArray();
          }]);
      }])->orderBy('id desc'),

'pagination' => [
'pageSize' => 100,
],
Expand Down