diff --git a/src/Entity.php b/src/Entity.php index 637603b1..e0582095 100644 --- a/src/Entity.php +++ b/src/Entity.php @@ -778,6 +778,8 @@ public function save(array | object $data = [], $where = []): bool $this->relationSave($relations); } + // 重置原始数据 + $this->setWeakMap('origin', $data); return true; } @@ -798,7 +800,7 @@ protected function autoDateTime(array &$data, bool $update) foreach ($dateTimeFields as $field) { if (is_string($field)) { $data[$field] = $this->getDateTime($field); - $this->$field = $this->readTransform($data[$field], $this->getFields($field)); + $this->setData($field, $this->readTransform($data[$field], $this->getFields($field))); } } } @@ -926,6 +928,7 @@ public function isSimple(): bool public function delete(): bool { if ($this->isVirtual() || $this->isView()) { + $this->clear(); return true; } @@ -948,6 +951,7 @@ public function delete(): bool $this->relationDelete($relations); } + $this->clear(); return true; } @@ -1099,6 +1103,20 @@ public function data(array $data) return $this; } + /** + * 清空模型数据. + * + * @return $this + */ + public function clear() + { + self::$weakMap[$this]['data'] = []; + self::$weakMap[$this]['origin'] = []; + self::$weakMap[$this]['get'] = []; + self::$weakMap[$this]['relation'] = []; + return $this; + } + /** * 获取原始数据. *