From 293dce863993c12f8922d55756472a6fc4fad375 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Wed, 28 Dec 2016 14:58:43 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Model.php | 4 +++- library/think/db/Query.php | 12 ++++++------ library/think/model/relation/OneToOne.php | 1 + 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/library/think/Model.php b/library/think/Model.php index 85b4cedd..2fa51f0f 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -439,7 +439,9 @@ abstract class Model implements \JsonSerializable, \ArrayAccess $value = $this->readTransform($value, $this->type[$name]); } elseif ($notFound) { $method = Loader::parseName($name, 1, false); - if (method_exists($this, $method) && $this->$method()->removeOption() instanceof Relation) { + if (method_exists($this, $method) && $this->$method() instanceof Relation) { + // 清空之前的查询参数 + $this->$method()->removeOption(); // 不存在该字段 获取关联数据 $value = $this->$method()->getRelation(); // 保存关联对象值 diff --git a/library/think/db/Query.php b/library/think/db/Query.php index c4fd0dc1..af09a975 100644 --- a/library/think/db/Query.php +++ b/library/think/db/Query.php @@ -1000,16 +1000,16 @@ class Query } /** - * 去除某个查询参数 + * 去除查询参数 * @access public - * @param string $option 参数名 + * @param string|bool $option 参数名 true 表示去除所有参数 * @return $this */ - public function removeOption($option = '') + public function removeOption($option = true) { - if ('' === $option) { + if (true === $option) { $this->options = []; - } elseif (isset($this->options[$option])) { + } elseif (is_string($option) && isset($this->options[$option])) { unset($this->options[$option]); } return $this; @@ -1660,7 +1660,7 @@ class Query /** @var Relation $model */ $relation = Loader::parseName($relation, 1, false); - $model = $class->$relation()->removeOption(); + $model = $class->$relation(); if ($model instanceof OneToOne && 0 == $model->getEagerlyType()) { $model->eagerly($this, $relation, $subRelation, $closure, $first); $first = false; diff --git a/library/think/model/relation/OneToOne.php b/library/think/model/relation/OneToOne.php index 0f22898b..7b989ef9 100644 --- a/library/think/model/relation/OneToOne.php +++ b/library/think/model/relation/OneToOne.php @@ -160,6 +160,7 @@ abstract class OneToOne extends Relation */ public function getEagerlyType() { + $this->removeOption(); return $this->eagerlyType; }