From 7a81110f6bcf60a4810bebc53607ed1d9a8342a1 Mon Sep 17 00:00:00 2001 From: Carsten Brandt Date: Tue, 17 Dec 2013 17:01:01 +0100 Subject: [PATCH] make ActiveRelation reusable fixes #1560 --- framework/yii/db/ActiveRelation.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/framework/yii/db/ActiveRelation.php b/framework/yii/db/ActiveRelation.php index b016c5c..0659ee3 100644 --- a/framework/yii/db/ActiveRelation.php +++ b/framework/yii/db/ActiveRelation.php @@ -63,6 +63,7 @@ class ActiveRelation extends ActiveQuery implements ActiveRelationInterface public function createCommand($db = null) { if ($this->primaryModel !== null) { + $where = $this->where; // lazy loading if ($this->via instanceof self) { // via pivot table @@ -84,6 +85,9 @@ class ActiveRelation extends ActiveQuery implements ActiveRelationInterface } else { $this->filterByModels([$this->primaryModel]); } + $command = parent::createCommand($db); + $this->where = $where; + return $command; } return parent::createCommand($db); }