This commit is contained in:
2021-03-05 18:17:01 +08:00
parent 8d9e3756c7
commit 6849212c7f
+18 -8
View File
@@ -827,7 +827,7 @@ abstract class BaseActiveRecord extends Component implements IOrm, ArrayAccess
public function refresh(): static
{
$this->_oldAttributes = $this->_attributes;
return $this;
return $this;
}
/**
@@ -864,16 +864,26 @@ abstract class BaseActiveRecord extends Component implements IOrm, ArrayAccess
return static::getColumns()->_decode($name, $value);
}
if (in_array($name, $this->_with)) {
$data = $this->{$this->_relate[$name]}();
if ($data instanceof HasBase) {
return $data->get();
}
return $data;
return $this->with($name);
}
return parent::__get($name);
}
/**
* @param $name
* @return mixed
*/
private function with($name): mixed
{
$data = $this->{$this->_relate[$name]}();
if ($data instanceof HasBase) {
return $data->get();
}
return $data;
}
/**
* @param string $type
* @return array
@@ -1032,8 +1042,8 @@ abstract class BaseActiveRecord extends Component implements IOrm, ArrayAccess
return new $className();
});
$model->_attributes = $data;
$model->setIsCreate(false);
$model->refresh();
$model->setIsCreate(false);
$model->refresh();
return $model;
}