From 97f82a1a9d8d6eabd62906a859a235c68272d0d1 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Wed, 27 Dec 2017 21:19:52 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E6=94=B9=E8=BF=9Bmodel=E7=B1=BB=E7=9A=84sa?= =?UTF-8?q?ve=E6=96=B9=E6=B3=95=E7=9A=84=E5=A4=8D=E5=90=88=E4=B8=BB?= =?UTF-8?q?=E9=94=AE=E5=8C=85=E5=90=AB=E8=87=AA=E5=A2=9E=E7=9A=84=E6=83=85?= =?UTF-8?q?=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; + } } } From 61235ed60af3185d72d16aa944a5bc60e855f452 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Wed, 27 Dec 2017 21:25:21 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=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 | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/library/think/Model.php b/library/think/Model.php index 40608296..99105caa 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -1124,10 +1124,9 @@ abstract class Model implements \JsonSerializable, \ArrayAccess // 获取自动增长主键 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; + foreach ((array) $pk as $key) { + if (!isset($this->data[$key]) || '' == $this->data[$key]) { + $this->data[$key] = $insertId; } } } From 7ccf303cf6b6a4999e24a63a440edc9aa2529363 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Wed, 27 Dec 2017 21:51:11 +0800 Subject: [PATCH 3/4] =?UTF-8?q?save=E6=96=B9=E6=B3=95=E6=94=B9=E8=BF=9B?= =?UTF-8?q?=E5=A4=8D=E5=90=88=E4=B8=BB=E9=94=AE=E7=9A=84=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Model.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/library/think/Model.php b/library/think/Model.php index 99105caa..391f78b6 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -1070,12 +1070,17 @@ abstract class Model implements \JsonSerializable, \ArrayAccess } } - if (is_string($pk) && isset($data[$pk])) { - if (!isset($where[$pk])) { - unset($where); - $where[$pk] = $data[$pk]; + $array = []; + + foreach ((array) $pk as $key) { + if (isset($data[$key])) { + $array[] = [$key, '=', $data[$key]]; + unset($data[$key]); } - unset($data[$pk]); + } + + if (!empty($array)) { + $where = $array; } // 检测字段 From 4ed42ca9ee798995c5bb22a0564f699359cd0cd2 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Wed, 27 Dec 2017 23:43:23 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Model.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/think/Model.php b/library/think/Model.php index 391f78b6..d2f7b640 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -1074,7 +1074,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess foreach ((array) $pk as $key) { if (isset($data[$key])) { - $array[] = [$key, '=', $data[$key]]; + $array[$key] = $data[$key]; unset($data[$key]); } }