diff --git a/library/think/Model.php b/library/think/Model.php index e5de7120..f0544d08 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -345,11 +345,12 @@ abstract class Model implements \JsonSerializable, \ArrayAccess if ($this->isUpdate) { // 更新数据 + // 自动更新 + $this->autoCompleteData($this->update); + if (false === $this->trigger('before_update', $this)) { return false; } - // 自动更新 - $this->autoCompleteData($this->update); // 去除没有更新的字段 foreach ($this->data as $key => $val) { @@ -368,13 +369,13 @@ abstract class Model implements \JsonSerializable, \ArrayAccess $this->trigger('after_update', $this); } else { // 新增数据 + // 自动写入 + $this->autoCompleteData($this->insert); + if (false === $this->trigger('before_insert', $this)) { return false; } - // 自动写入 - $this->autoCompleteData($this->insert); - $result = self::db()->insert($this->data); // 获取自动增长主键