From d0cc9a7146629c454d8d6084a76c4fbd16712a2b Mon Sep 17 00:00:00 2001 From: thinkphp Date: Wed, 19 Oct 2016 17:23:34 +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=20=E6=96=B0=E5=A2=9E=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E7=9A=84=E6=97=B6=E5=80=99=E6=B7=BB=E5=8A=A0=E4=B8=8D=E6=98=AF?= =?UTF-8?q?=E8=87=AA=E5=A2=9E=E4=B8=BB=E9=94=AE=E7=9A=84=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Model.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/library/think/Model.php b/library/think/Model.php index a96c7d6e..561792aa 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -649,7 +649,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess if (false === $this->trigger('before_write', $this)) { return false; } - + $pk = $this->getPk(); if ($this->isUpdate) { // 自动更新 $this->autoCompleteData($this->update); @@ -680,7 +680,6 @@ abstract class Model implements \JsonSerializable, \ArrayAccess $where = $this->updateWhere; } - $pk = $this->getPk(); if (is_string($pk) && isset($data[$pk])) { if (!isset($where[$pk])) { unset($where); @@ -710,10 +709,9 @@ abstract class Model implements \JsonSerializable, \ArrayAccess $result = $this->db()->insert($this->data); // 获取自动增长主键 - if ($result) { + if ($result && is_string($pk) && !isset($this->data[$pk])) { $insertId = $this->db()->getLastInsID($sequence); - $pk = $this->getPk(); - if (is_string($pk) && $insertId) { + if ($insertId) { $this->data[$pk] = $insertId; } }