This commit is contained in:
2021-11-11 03:14:52 +08:00
parent 07a40f4449
commit c13d4101b9
3 changed files with 8 additions and 4 deletions
+1 -1
View File
@@ -134,7 +134,7 @@ abstract class AbstractCollection extends Component implements \IteratorAggregat
return NULL; return NULL;
} }
if (!($this->_item[$offset] instanceof ModelInterface)) { if (!($this->_item[$offset] instanceof ModelInterface)) {
return $this->model->setAttributes($this->_item[$offset]); return $this->model::populate($this->_item[$offset]);
} }
return $this->_item[$offset]; return $this->_item[$offset];
} }
+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->setAttributes($current); return $this->model::populate($current);
} }
+6 -2
View File
@@ -512,7 +512,9 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, T
if (empty($param)) { if (empty($param)) {
return $this; return $this;
} }
$this->_attributes = $param; foreach ($this->_attributes as $key => $attribute) {
$this->_attributes[$key] = $this->_setter($key, $attribute);
}
return $this; return $this;
} }
@@ -525,7 +527,9 @@ 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;
} }
$this->_oldAttributes = $param; foreach ($this->_oldAttributes as $key => $attribute) {
$this->_oldAttributes[$key] = $this->_setter($key, $attribute);
}
return $this; return $this;
} }