From 97f82a1a9d8d6eabd62906a859a235c68272d0d1 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Wed, 27 Dec 2017 21:19:52 +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=E7=9A=84=E5=A4=8D=E5=90=88=E4=B8=BB=E9=94=AE?= =?UTF-8?q?=E5=8C=85=E5=90=AB=E8=87=AA=E5=A2=9E=E7=9A=84=E6=83=85=E5=86=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Model.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/library/think/Model.php b/library/think/Model.php index 31ef5e4c..40608296 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -1123,10 +1123,12 @@ abstract class Model implements \JsonSerializable, \ArrayAccess } // 获取自动增长主键 - if ($result && is_string($pk) && (!isset($this->data[$pk]) || '' == $this->data[$pk])) { - $insertId = $this->getQuery()->getLastInsID($sequence); - if ($insertId) { - $this->data[$pk] = $insertId; + if ($result && $insertId = $this->getQuery()->getLastInsID($sequence)) { + $pks = (array) $pk; + foreach ($pks as $pk) { + if (!isset($this->data[$pk]) || '' == $this->data[$pk]) { + $this->data[$pk] = $insertId; + } } }