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 public function refresh(): static
{ {
$this->_oldAttributes = $this->_attributes; $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); return static::getColumns()->_decode($name, $value);
} }
if (in_array($name, $this->_with)) { if (in_array($name, $this->_with)) {
$data = $this->{$this->_relate[$name]}(); return $this->with($name);
if ($data instanceof HasBase) {
return $data->get();
}
return $data;
} }
return parent::__get($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 * @param string $type
* @return array * @return array
@@ -1032,8 +1042,8 @@ abstract class BaseActiveRecord extends Component implements IOrm, ArrayAccess
return new $className(); return new $className();
}); });
$model->_attributes = $data; $model->_attributes = $data;
$model->setIsCreate(false); $model->setIsCreate(false);
$model->refresh(); $model->refresh();
return $model; return $model;
} }