This commit is contained in:
2022-09-29 22:51:41 +08:00
parent 7554f6b161
commit f87a3c386f
4 changed files with 32 additions and 63 deletions
+2 -18
View File
@@ -19,23 +19,7 @@ use Exception;
*/
class HasOne extends HasBase
{
/**
* @param $name
* @param $arguments
* @return static
*/
public function __call($name, $arguments)
{
if (!method_exists($this, $name)) {
$key = $this->model::className() . '_' . $this->primaryId . '_' . $this->value;
$this->_relation->getQuery($key)->$name(...$arguments);
} else {
call_user_func([$this, $name], ...$arguments);
}
return $this;
}
/**
* @return array|null|ModelInterface
* @throws Exception
@@ -43,6 +27,6 @@ class HasOne extends HasBase
public function get(): array|ModelInterface|null
{
$key = $this->model::className() . '_' . $this->primaryId . '_' . $this->value;
return $this->_relation->first($key);
return $this->_relation->first(md5($key));
}
}