This commit is contained in:
2021-11-11 03:03:40 +08:00
parent 8b164c7611
commit 8c3d3b2ce0
2 changed files with 11 additions and 14 deletions
+1 -1
View File
@@ -56,7 +56,7 @@ class CollectionIterator extends \ArrayIterator
*/ */
protected function newModel($current): ModelInterface protected function newModel($current): ModelInterface
{ {
return $this->model->attributes = $current; return $this->model->setAttributes($current);
} }
+5 -8
View File
@@ -123,6 +123,7 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, T
/** /**
* @param string $name * @param string $name
* @param mixed $value * @param mixed $value
* @return mixed
*/ */
private function _setter(string $name, mixed $value): mixed private function _setter(string $name, mixed $value): mixed
{ {
@@ -488,7 +489,7 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, T
*/ */
public function setAttribute($name, $value): mixed public function setAttribute($name, $value): mixed
{ {
return $this->_attributes[$name] = $this->_setter($name, $value); return $this->_attributes[$name] = $value;
} }
/** /**
@@ -498,7 +499,7 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, T
*/ */
public function setOldAttribute($name, $value): mixed public function setOldAttribute($name, $value): mixed
{ {
return $this->_oldAttributes[$name] = $this->_setter($name, $value); return $this->_oldAttributes[$name] = $value;
} }
/** /**
@@ -511,9 +512,7 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, T
if (empty($param)) { if (empty($param)) {
return $this; return $this;
} }
foreach ($param as $key => $value) { $this->_attributes = $param;
$this->_attributes[$key] = $this->_setter($key, $value);
}
return $this; return $this;
} }
@@ -526,9 +525,7 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, T
if (empty($param) || !is_array($param)) { if (empty($param) || !is_array($param)) {
return $this; return $this;
} }
foreach ($param as $key => $val) { $this->_oldAttributes = $param;
$this->setOldAttribute($key, $val);
}
return $this; return $this;
} }