From a7222baf9ba8e47d59efe10d189616142b2774be Mon Sep 17 00:00:00 2001 From: thinkphp Date: Thu, 4 Feb 2016 11:51:01 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3Model=E7=B1=BB=E7=9A=84add?= =?UTF-8?q?=E5=92=8Csave=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 | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/library/think/Model.php b/library/think/Model.php index c9781fe8..8b14b2f6 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -285,7 +285,7 @@ class Model // 写入数据到数据库 $result = $this->db->insert($data, $options, $replace); if (false !== $result && is_numeric($result)) { - $pk = $this->getPk(); + $pk = $this->getPk($options['table']); // 增加复合主键支持 if (is_array($pk)) { return $result; @@ -340,7 +340,7 @@ class Model $data = $this->_write_data($data, 'update'); // 分析表达式 $options = $this->_parseOptions(); - $pk = $this->getPk(); + $pk = $this->getPk($options['table']); if (!isset($options['where'])) { // 如果存在主键数据 则自动作为更新条件 if (is_string($pk) && isset($data[$pk])) { @@ -914,7 +914,8 @@ class Model } // 状态 - $type = $type ? $type : (!empty($data[$this->getPk()]) ? self::MODEL_UPDATE : self::MODEL_INSERT); + $pk = $this->getPk(); + $type = $type ? $type : (is_string($pk) && !empty($data[$pk]) ? self::MODEL_UPDATE : self::MODEL_INSERT); // 检测提交字段的合法性 if (isset($this->options['field'])) {