From 5cc1448a832aef29af5407896d36a6bda1cfbb7e Mon Sep 17 00:00:00 2001 From: thinkphp Date: Sat, 20 Aug 2016 14:47:23 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9Bsaveall=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 | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/library/think/Model.php b/library/think/Model.php index e15b37d6..09e53958 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -730,7 +730,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess * @access public * @param array $dataSet 数据 * @param boolean $replace 是否自动识别更新和写入 - * @return array|false + * @return array */ public function saveAll($dataSet, $replace = true) { @@ -738,8 +738,12 @@ abstract class Model implements \JsonSerializable, \ArrayAccess $db = $this->db(); $db->startTrans(); try { + $pk = $this->getPk(); + if (is_string($pk) && $replace) { + $auto = true; + } foreach ($dataSet as $key => $data) { - if ($replace && isset($data[$this->getPk()])) { + if (!empty($auto) && isset($data[$pk])) { $result[$key] = self::update($data); } else { $result[$key] = self::create($data);