改名
This commit is contained in:
@@ -28,16 +28,16 @@ use JetBrains\PhpStorm\Pure;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array $handler
|
* @param array $handler
|
||||||
* @return mixed
|
* @return bool
|
||||||
*/
|
*/
|
||||||
#[Pure] public function execute(array $handler): mixed
|
public function execute(array $handler): bool
|
||||||
{
|
{
|
||||||
// /** @var ActiveRecord $activeRecord */
|
/** @var ActiveRecord $activeRecord */
|
||||||
// [$activeRecord, $method] = $handler;
|
[$activeRecord, $method] = $handler;
|
||||||
//
|
|
||||||
// $activeRecord->setRelate($this->name, $method);
|
|
||||||
|
|
||||||
return parent::execute($handler);
|
$activeRecord->setRelate($this->name, $method);
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -235,14 +235,7 @@ class ActiveQuery extends Component implements ISqlBuilder
|
|||||||
if (empty($this->with) || !is_array($this->with)) {
|
if (empty($this->with) || !is_array($this->with)) {
|
||||||
return $model;
|
return $model;
|
||||||
}
|
}
|
||||||
foreach ($this->with as $val) {
|
return $model->setWith($this->with);
|
||||||
$method = 'get' . ucfirst($val);
|
|
||||||
if (!method_exists($model, $method)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
$model->setRelate($val, $method);
|
|
||||||
}
|
|
||||||
return $model;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -245,7 +245,7 @@ class ActiveRecord extends BaseActiveRecord
|
|||||||
*/
|
*/
|
||||||
private function resolveObject($method): mixed
|
private function resolveObject($method): mixed
|
||||||
{
|
{
|
||||||
$resolve = $this->$method();
|
$resolve = $this->{$this->getRelate($method)}();
|
||||||
if ($resolve instanceof HasBase) {
|
if ($resolve instanceof HasBase) {
|
||||||
$resolve = $resolve->get();
|
$resolve = $resolve->get();
|
||||||
}
|
}
|
||||||
@@ -296,11 +296,11 @@ class ActiveRecord extends BaseActiveRecord
|
|||||||
private function runRelate(): array
|
private function runRelate(): array
|
||||||
{
|
{
|
||||||
$relates = [];
|
$relates = [];
|
||||||
if (empty($this->_relate)) {
|
if (empty($this->_with)) {
|
||||||
return $relates;
|
return $relates;
|
||||||
}
|
}
|
||||||
foreach ($this->_relate as $key => $val) {
|
foreach ($this->_with as $val) {
|
||||||
$relates[$key] = $this->resolveObject($val);
|
$relates[$val] = $this->resolveObject($val);
|
||||||
}
|
}
|
||||||
return $relates;
|
return $relates;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -143,6 +143,17 @@ abstract class BaseActiveRecord extends Component implements IOrm, ArrayAccess
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $data
|
||||||
|
* @return BaseActiveRecord
|
||||||
|
*/
|
||||||
|
public function setWith($data): static
|
||||||
|
{
|
||||||
|
$this->_with = $data;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $name
|
* @param $name
|
||||||
* @param $method
|
* @param $method
|
||||||
|
|||||||
Reference in New Issue
Block a user