From 5a70087133671c6d3a66202badaf62b746fe20ca Mon Sep 17 00:00:00 2001 From: thinkphp Date: Sat, 9 Apr 2016 13:13:15 +0800 Subject: [PATCH] =?UTF-8?q?model=E6=94=B9=E8=BF=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Model.php | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/library/think/Model.php b/library/think/Model.php index f0544d08..4a636ba1 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -337,24 +337,26 @@ abstract class Model implements \JsonSerializable, \ArrayAccess if (!$this->validateData()) { return false; } - if (false === $this->trigger('before_write', $this)) { - return false; - } + // 数据自动完成 $this->autoCompleteData($this->auto); + // 事件回调 + if (false === $this->trigger('before_write', $this)) { + return false; + } + if ($this->isUpdate) { - // 更新数据 // 自动更新 $this->autoCompleteData($this->update); - + // 事件回调 if (false === $this->trigger('before_update', $this)) { return false; } // 去除没有更新的字段 foreach ($this->data as $key => $val) { - if (!in_array($key, $this->change) && !$this->isPk($key) && !isset($this->relation[$key])) { + if (!in_array($key, $this->change) && !$this->isPk($key)) { unset($this->data[$key]); } } @@ -368,7 +370,6 @@ abstract class Model implements \JsonSerializable, \ArrayAccess // 更新回调 $this->trigger('after_update', $this); } else { - // 新增数据 // 自动写入 $this->autoCompleteData($this->insert);