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); } /**