This commit is contained in:
2021-01-16 16:57:35 +08:00
parent b9dbba1dd5
commit eb622b8527
3 changed files with 19 additions and 14 deletions
+6 -4
View File
@@ -15,13 +15,15 @@ class HasCount extends HasBase
/** /**
* @param $name * @param $name
* @param $arguments * @param $arguments
* @return $this * @return ActiveQuery
* @throws Exception * @throws Exception
*/ */
public function __call($name, $arguments): static public function __call($name, $arguments): mixed
{ {
$this->_relation->getQuery($this->model::className())->$name(...$arguments); if (method_exists($this, $name)) {
return $this; return call_user_func([$this, $name], ...$arguments);
}
return $this->_relation->getQuery($this->model::className())->$name(...$arguments);
} }
/** /**
+6 -5
View File
@@ -22,13 +22,14 @@ class HasMany extends HasBase
/** /**
* @param $name * @param $name
* @param $arguments * @param $arguments
* @return static * @return ActiveQuery
* @throws Exception
*/ */
public function __call($name, $arguments): static public function __call($name, $arguments): mixed
{ {
$this->_relation->getQuery($this->model::className())->$name(...$arguments); if (method_exists($this, $name)) {
return $this; return call_user_func([$this, $name], ...$arguments);
}
return $this->_relation->getQuery($this->model::className())->$name(...$arguments);
} }
/** /**
+7 -5
View File
@@ -6,6 +6,7 @@
* Time: 13:47 * Time: 13:47
*/ */
declare(strict_types=1); declare(strict_types=1);
namespace Database; namespace Database;
use Exception; use Exception;
@@ -21,13 +22,14 @@ class HasOne extends HasBase
/** /**
* @param $name * @param $name
* @param $arguments * @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); if (method_exists($this, $name)) {
return $this; return call_user_func([$this, $name], ...$arguments);
}
return $this->_relation->getQuery($this->model::className())->$name(...$arguments);
} }
/** /**