From aebbf980a5ed1898ebcafa2de2e8fbea8e7defe2 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Mon, 24 Apr 2017 13:58:59 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E5=85=B3=E8=81=94=E5=AE=9A?= =?UTF-8?q?=E4=B9=89=E7=9A=84=E4=B8=80=E4=BA=9B=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/model/relation/BelongsToMany.php | 6 +++--- library/think/model/relation/HasManyThrough.php | 2 +- library/think/model/relation/MorphMany.php | 2 +- library/think/model/relation/MorphOne.php | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/library/think/model/relation/BelongsToMany.php b/library/think/model/relation/BelongsToMany.php index d684fa23..341e0a76 100644 --- a/library/think/model/relation/BelongsToMany.php +++ b/library/think/model/relation/BelongsToMany.php @@ -121,7 +121,7 @@ class BelongsToMany extends Relation public function getRelation($subRelation = '', $closure = null) { if ($closure) { - call_user_func_array($closure, [& $this->query]); + call_user_func_array($closure, [ & $this->query]); } $result = $this->buildQuery()->relation($subRelation)->select(); $this->hydratePivot($result); @@ -514,7 +514,7 @@ class BelongsToMany extends Relation $changes = [ 'attached' => [], 'detached' => [], - 'updated' => [] + 'updated' => [], ]; $pk = $this->parent->getPk(); $current = $this->pivot->where($this->localKey, $this->parent->$pk) @@ -559,7 +559,7 @@ class BelongsToMany extends Relation */ protected function baseQuery() { - if (empty($this->baseQuery)) { + if (empty($this->baseQuery) && $this->parent->getData()) { $pk = $this->parent->getPk(); $table = $this->pivot->getTable(); $this->query->join($table . ' pivot', 'pivot.' . $this->foreignKey . '=' . $this->query->getTable() . '.' . $this->query->getPk())->where('pivot.' . $this->localKey, $this->parent->$pk); diff --git a/library/think/model/relation/HasManyThrough.php b/library/think/model/relation/HasManyThrough.php index 4d9240c5..7d0d5124 100644 --- a/library/think/model/relation/HasManyThrough.php +++ b/library/think/model/relation/HasManyThrough.php @@ -128,7 +128,7 @@ class HasManyThrough extends Relation */ protected function baseQuery() { - if (empty($this->baseQuery)) { + if (empty($this->baseQuery) && $this->parent->getData()) { $through = $this->through; $model = $this->model; $alias = Loader::parseName(basename(str_replace('\\', '/', $model))); diff --git a/library/think/model/relation/MorphMany.php b/library/think/model/relation/MorphMany.php index d37af144..a4a2f500 100644 --- a/library/think/model/relation/MorphMany.php +++ b/library/think/model/relation/MorphMany.php @@ -273,7 +273,7 @@ class MorphMany extends Relation */ protected function baseQuery() { - if (empty($this->baseQuery)) { + if (empty($this->baseQuery) && $this->parent->getData()) { $pk = $this->parent->getPk(); $map[$this->morphKey] = $this->parent->$pk; $map[$this->morphType] = $this->type; diff --git a/library/think/model/relation/MorphOne.php b/library/think/model/relation/MorphOne.php index e22198bb..f8124ee3 100644 --- a/library/think/model/relation/MorphOne.php +++ b/library/think/model/relation/MorphOne.php @@ -217,7 +217,7 @@ class MorphOne extends Relation */ protected function baseQuery() { - if (empty($this->baseQuery)) { + if (empty($this->baseQuery) && $this->parent->getData()) { $pk = $this->parent->getPk(); $map[$this->morphKey] = $this->parent->$pk; $map[$this->morphType] = $this->type;