From 4248b05e0cff923f6d5c31bb4f55cbcacc21fd6b Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 24 Dec 2024 10:16:09 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0clear=E6=96=B9=E6=B3=95=20?= =?UTF-8?q?=E6=B8=85=E7=A9=BA=E6=A8=A1=E5=9E=8B=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Entity.php | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) 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; + } + /** * 获取原始数据. *