From cd442339dfc4d77859054ee009e3711fb21d0193 Mon Sep 17 00:00:00 2001 From: Alexander Makarov Date: Sat, 8 Sep 2018 00:37:22 +0300 Subject: [PATCH] Revert "Fixes #16552: Added check in `yii\db\ActiveQuery::prepare()` to prevent populating already populated relation when another relation is requested with `via`" This reverts commit f69612f7927ee8e599a22a0b83b73f64b628b8f0. --- framework/CHANGELOG.md | 1 - framework/db/ActiveQuery.php | 16 ++++------------ 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index 82b2379..be266f2 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -44,7 +44,6 @@ Yii Framework 2 Change Log - Bug #16377: Fixed `yii\base\Event:off()` undefined index error when event handler does not match (razvanphp) - Bug #16514: Fixed `yii\di\Container::resolveCallableDependencies` to support callable object (wi1dcard) - Bug #15889: Fixed override `yii\helpers\Html::setActivePlaceholder` (lesha724) -- Bug #16552: Added check in `yii\db\ActiveQuery::prepare()` to prevent populating already populated relation when another relation is requested with `via` (drlibra) - Enh #16522: Allow jQuery 3.3 (Slamdunk) - Enh #16603: Added `yii\mutex\FileMutex::$isWindows` for Windows file shares on Unix guest machines (brandonkelly) - Bug #16666: Fixed `yii\helpers\ArrayHelper::merge` (rustamwin) diff --git a/framework/db/ActiveQuery.php b/framework/db/ActiveQuery.php index 5af019e..46086fb 100644 --- a/framework/db/ActiveQuery.php +++ b/framework/db/ActiveQuery.php @@ -172,19 +172,11 @@ class ActiveQuery extends Query implements ActiveQueryInterface /* @var $viaQuery ActiveQuery */ list($viaName, $viaQuery) = $this->via; if ($viaQuery->multiple) { - if ($this->primaryModel->isRelationPopulated($viaName)) { - $viaModels = $this->primaryModel->$viaName; - } else { - $viaModels = $viaQuery->all(); - $this->primaryModel->populateRelation($viaName, $viaModels); - } + $viaModels = $viaQuery->all(); + $this->primaryModel->populateRelation($viaName, $viaModels); } else { - if ($this->primaryModel->isRelationPopulated($viaName)) { - $model = $this->primaryModel->$viaName; - } else { - $model = $viaQuery->one(); - $this->primaryModel->populateRelation($viaName, $model); - } + $model = $viaQuery->one(); + $this->primaryModel->populateRelation($viaName, $model); $viaModels = $model === null ? [] : [$model]; } $this->filterByModels($viaModels);