diff --git a/library/think/db/Query.php b/library/think/db/Query.php index 7bc75c3d..c4fd0dc1 100644 --- a/library/think/db/Query.php +++ b/library/think/db/Query.php @@ -1005,9 +1005,11 @@ class Query * @param string $option 参数名 * @return $this */ - public function removeOption($option) + public function removeOption($option = '') { - if (isset($this->options[$option])) { + if ('' === $option) { + $this->options = []; + } elseif (isset($this->options[$option])) { unset($this->options[$option]); } return $this; @@ -1658,7 +1660,7 @@ class Query /** @var Relation $model */ $relation = Loader::parseName($relation, 1, false); - $model = $class->$relation(); + $model = $class->$relation()->removeOption(); if ($model instanceof OneToOne && 0 == $model->getEagerlyType()) { $model->eagerly($this, $relation, $subRelation, $closure, $first); $first = false; diff --git a/library/think/model/Relation.php b/library/think/model/Relation.php index 4fc68ff2..9766ce2e 100644 --- a/library/think/model/Relation.php +++ b/library/think/model/Relation.php @@ -92,6 +92,17 @@ abstract class Relation return $this; } + /** + * 移除关联查询参数 + * @access public + * @return $this + */ + public function removeOption() + { + $this->query->removeOption(); + return $this; + } + public function __call($method, $args) { if ($this->query) {