From 172ff8f14a62f83f5c060c47b704b1d5ce80561b Mon Sep 17 00:00:00 2001 From: thinkphp Date: Sun, 19 Mar 2023 12:43:50 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=96=E6=B6=88lazySave=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Model.php | 35 -------------------------------- src/model/concern/SoftDelete.php | 2 -- 2 files changed, 37 deletions(-) diff --git a/src/Model.php b/src/Model.php index ac822999..0f5b47fe 100644 --- a/src/Model.php +++ b/src/Model.php @@ -129,13 +129,6 @@ abstract class Model implements JsonSerializable, ArrayAccess, Arrayable, Jsonab */ protected $globalScope = []; - /** - * 延迟保存信息. - * - * @var bool - */ - private $lazySave = false; - /** * Db对象 * @@ -531,22 +524,6 @@ public function isEmpty(): bool return empty($this->data); } - /** - * 延迟保存当前数据对象 - * - * @param array|bool $data 数据 - * - * @return void - */ - public function lazySave(array|bool $data = []): void - { - if (is_array($data)) { - $this->setAttrs($data); - } - - $this->lazySave = false === $data ? false : true; - } - /** * 保存当前数据对象 * @@ -580,7 +557,6 @@ public function save(array|Model $data = [], string $sequence = null): bool // 重新记录原始数据 $this->origin = $this->data; $this->get = []; - $this->lazySave = false; return true; } @@ -854,7 +830,6 @@ public function delete(): bool $this->trigger('AfterDelete'); $this->exists = false; - $this->lazySave = false; return true; } @@ -1096,14 +1071,4 @@ public static function __callStatic($method, $args) return call_user_func_array([$model->db(), $method], $args); } - - /** - * 析构方法. - */ - public function __destruct() - { - if ($this->lazySave) { - $this->save(); - } - } } diff --git a/src/model/concern/SoftDelete.php b/src/model/concern/SoftDelete.php index 4bfc64e5..cc6da7b9 100644 --- a/src/model/concern/SoftDelete.php +++ b/src/model/concern/SoftDelete.php @@ -104,8 +104,6 @@ public function delete(): bool ->where($where) ->removeOption('soft_delete') ->delete(); - - $this->lazySave(false); } // 关联删除