From eb622b8527548c7a3d41abe0b8c10bdd863959a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Sat, 16 Jan 2021 16:57:35 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Database/HasCount.php | 10 ++++++---- Database/HasMany.php | 11 ++++++----- Database/HasOne.php | 12 +++++++----- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/Database/HasCount.php b/Database/HasCount.php index dc0cbd1d..f39173a4 100644 --- a/Database/HasCount.php +++ b/Database/HasCount.php @@ -15,13 +15,15 @@ class HasCount extends HasBase /** * @param $name * @param $arguments - * @return $this + * @return ActiveQuery * @throws Exception */ - public function __call($name, $arguments): static + public function __call($name, $arguments): mixed { - $this->_relation->getQuery($this->model::className())->$name(...$arguments); - return $this; + if (method_exists($this, $name)) { + return call_user_func([$this, $name], ...$arguments); + } + return $this->_relation->getQuery($this->model::className())->$name(...$arguments); } /** diff --git a/Database/HasMany.php b/Database/HasMany.php index 561fb70e..4280a4d3 100644 --- a/Database/HasMany.php +++ b/Database/HasMany.php @@ -22,13 +22,14 @@ class HasMany extends HasBase /** * @param $name * @param $arguments - * @return static - * @throws Exception + * @return ActiveQuery */ - public function __call($name, $arguments): static + public function __call($name, $arguments): mixed { - $this->_relation->getQuery($this->model::className())->$name(...$arguments); - return $this; + if (method_exists($this, $name)) { + return call_user_func([$this, $name], ...$arguments); + } + return $this->_relation->getQuery($this->model::className())->$name(...$arguments); } /** diff --git a/Database/HasOne.php b/Database/HasOne.php index ac63aea7..5ec632e8 100644 --- a/Database/HasOne.php +++ b/Database/HasOne.php @@ -6,6 +6,7 @@ * Time: 13:47 */ declare(strict_types=1); + namespace Database; use Exception; @@ -21,13 +22,14 @@ class HasOne extends HasBase /** * @param $name * @param $arguments - * @return $this - * @throws Exception + * @return ActiveQuery */ - public function __call($name, $arguments): static + public function __call($name, $arguments): mixed { - $this->_relation->getQuery($this->model::className())->$name(...$arguments); - return $this; + if (method_exists($this, $name)) { + return call_user_func([$this, $name], ...$arguments); + } + return $this->_relation->getQuery($this->model::className())->$name(...$arguments); } /**