Files
kiri-core/Database/HasOne.php
T

46 lines
801 B
PHP
Raw Normal View History

2020-08-31 12:38:32 +08:00
<?php
/**
* Created by PhpStorm.
* User: whwyy
* Date: 2018/4/4 0004
* Time: 13:47
*/
2020-10-29 18:17:25 +08:00
declare(strict_types=1);
2021-01-16 16:57:35 +08:00
2020-08-31 12:38:32 +08:00
namespace Database;
use Exception;
2021-02-25 18:56:37 +08:00
use Database\Traits\HasBase;
2020-08-31 12:38:32 +08:00
/**
* Class HasOne
* @package Database
* @internal Query
*/
class HasOne extends HasBase
{
/**
* @param $name
* @param $arguments
2021-01-16 16:57:35 +08:00
* @return ActiveQuery
2020-08-31 12:38:32 +08:00
*/
2021-01-16 16:57:35 +08:00
public function __call($name, $arguments): mixed
2020-08-31 12:38:32 +08:00
{
2021-01-16 16:57:35 +08:00
if (method_exists($this, $name)) {
return call_user_func([$this, $name], ...$arguments);
}
2021-01-26 17:12:26 +08:00
$this->_relation->getQuery($this->model::className())->$name(...$arguments);
return $this;
2020-08-31 12:38:32 +08:00
}
/**
* @return array|null|ActiveRecord
* @throws Exception
*/
2020-12-17 14:09:14 +08:00
public function get(): array|ActiveRecord|null
2020-08-31 12:38:32 +08:00
{
return $this->_relation->first($this->model::className(), $this->value);
}
}