This commit is contained in:
2021-11-11 03:45:09 +08:00
parent 70f3714b15
commit 3e75bdc089
3 changed files with 15 additions and 5 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::populate($this->_item[$offset]); return $this->model->populates($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::populate($current); return $this->model->populates($current);
} }
+13 -3
View File
@@ -612,7 +612,6 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, T
*/ */
public function save($data = NULL): static|bool public function save($data = NULL): static|bool
{ {
var_dump($this->_attributes);
if (!is_null($data)) { if (!is_null($data)) {
$this->_attributes = merge($this->_attributes, $data); $this->_attributes = merge($this->_attributes, $data);
} }
@@ -621,13 +620,25 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, T
} }
[$change, $condition, $fields] = $this->separation(); [$change, $condition, $fields] = $this->separation();
if (!$this->isNewExample) { if (!$this->isNewExample) {
var_dump($fields, $condition, $change);
return $this->updateInternal($fields, $condition, $change); return $this->updateInternal($fields, $condition, $change);
} }
return $this->insert($change, $fields); return $this->insert($change, $fields);
} }
/**
* @param $value
* @return $this
*/
public function populates($value): static
{
$this->_attributes = $value;
$this->_oldAttributes = $value;
$this->setIsCreate(FALSE);
return $this;
}
/** /**
* @param array|null $rule * @param array|null $rule
* @return bool * @return bool
@@ -846,7 +857,6 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, T
public function refresh(): static public function refresh(): static
{ {
$this->_oldAttributes = $this->_attributes; $this->_oldAttributes = $this->_attributes;
var_dump($this->_attributes);
return $this; return $this;
} }