From 3774e3451aa483247366460e6fa76b0d58937499 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Wed, 4 May 2016 18:50:03 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9BModel=E7=B1=BB=E7=9A=84save?= =?UTF-8?q?=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Model.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/library/think/Model.php b/library/think/Model.php index ae100d17..46df0a68 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -263,13 +263,14 @@ abstract class Model implements \JsonSerializable, \ArrayAccess } // 去除没有更新的字段 + $data = []; foreach ($this->data as $key => $val) { - if (!in_array($key, $this->change) && !$this->isPk($key)) { - unset($this->data[$key]); + if (in_array($key, $this->change) || $this->isPk($key)) { + $data[$key] = $val; } } - $result = self::db()->where($where)->update($this->data); + $result = self::db()->where($where)->update($data); // 更新回调 $this->trigger('after_update', $this);