This commit is contained in:
2021-03-04 15:05:46 +08:00
parent 5d1a3b3533
commit 5a237cdd77
4 changed files with 23 additions and 19 deletions
+1 -8
View File
@@ -235,14 +235,7 @@ class ActiveQuery extends Component implements ISqlBuilder
if (empty($this->with) || !is_array($this->with)) {
return $model;
}
foreach ($this->with as $val) {
$method = 'get' . ucfirst($val);
if (!method_exists($model, $method)) {
continue;
}
$model->setRelate($val, $method);
}
return $model;
return $model->setWith($this->with);
}
/**
+4 -4
View File
@@ -245,7 +245,7 @@ class ActiveRecord extends BaseActiveRecord
*/
private function resolveObject($method): mixed
{
$resolve = $this->$method();
$resolve = $this->{$this->getRelate($method)}();
if ($resolve instanceof HasBase) {
$resolve = $resolve->get();
}
@@ -296,11 +296,11 @@ class ActiveRecord extends BaseActiveRecord
private function runRelate(): array
{
$relates = [];
if (empty($this->_relate)) {
if (empty($this->_with)) {
return $relates;
}
foreach ($this->_relate as $key => $val) {
$relates[$key] = $this->resolveObject($val);
foreach ($this->_with as $val) {
$relates[$val] = $this->resolveObject($val);
}
return $relates;
}
+11
View File
@@ -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 $method