From 6849212c7f5c7bdc95d892f039d1a9e51e581798 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Fri, 5 Mar 2021 18:17:01 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Database/Base/BaseActiveRecord.php | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/Database/Base/BaseActiveRecord.php b/Database/Base/BaseActiveRecord.php index 9e172b0f..84c8726a 100644 --- a/Database/Base/BaseActiveRecord.php +++ b/Database/Base/BaseActiveRecord.php @@ -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; }