From fb4f63266caebfe137ca211dc44284df79a519c9 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Thu, 7 Apr 2016 15:42:50 +0800 Subject: [PATCH] =?UTF-8?q?Model=E7=B1=BB=E7=9A=84save=E6=96=B9=E6=B3=95?= =?UTF-8?q?=E8=BF=94=E5=9B=9E=E5=80=BC=20=E4=B8=8D=E5=86=8D=E5=88=A4?= =?UTF-8?q?=E6=96=AD=20=E8=87=AA=E5=A2=9EID?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Model.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/library/think/Model.php b/library/think/Model.php index 870be43e..16638648 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -323,11 +323,12 @@ abstract class Model implements \JsonSerializable, \ArrayAccess $result = self::db()->insert($data); // 获取自动增长主键 - $insertId = self::db()->getLastInsID(); - if (is_string($this->pk) && $insertId) { - $data[$this->pk] = $insertId; + if ($result) { + $insertId = self::db()->getLastInsID(); + if (is_string($this->pk) && $insertId) { + $data[$this->pk] = $insertId; + } } - $result = $insertId ?: $result; // 数据对象赋值 $this->data = $data;