From b14c1a9dc298f041718449bfe1f75764cef52ed5 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 13 Sep 2016 22:54:22 +0800 Subject: [PATCH] =?UTF-8?q?Merge=E6=A8=A1=E5=9E=8Bsave=E6=96=B9=E6=B3=95?= =?UTF-8?q?=E5=92=8Cmodel=E7=B1=BB=E5=8F=82=E6=95=B0=E5=92=8C=E8=BF=94?= =?UTF-8?q?=E5=9B=9E=E5=80=BC=E7=BB=9F=E4=B8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/model/Merge.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/library/think/model/Merge.php b/library/think/model/Merge.php index 9a28ea9c..405c6bcc 100644 --- a/library/think/model/Merge.php +++ b/library/think/model/Merge.php @@ -144,11 +144,10 @@ class Merge extends Model * @access public * @param mixed $data 数据 * @param array $where 更新条件 - * @param bool $getId 新增的时候是否获取id - * @param bool $replace 是否replace - * @return mixed + * @param string $sequence 自增序列名 + * @return integer|false */ - public function save($data = [], $where = [], $getId = true, $replace = false) + public function save($data = [], $where = [], $sequence = null) { if (!empty($data)) { // 数据自动验证 @@ -230,11 +229,13 @@ class Merge extends Model // 处理模型数据 $data = $this->parseData($this->name, $this->data, true); // 写入主表数据 - $result = $db->name($this->name)->strict(false)->insert($data, $replace); + $result = $db->name($this->name)->strict(false)->insert($data); if ($result) { - $insertId = $db->getLastInsID(); + $insertId = $db->getLastInsID($sequence); // 写入外键数据 - $this->data[$this->fk] = $insertId; + if ($insertId) { + $this->data[$this->fk] = $insertId; + } // 写入附表数据 foreach (static::$relationModel as $key => $model) { @@ -245,7 +246,6 @@ class Merge extends Model $query = clone $db; $query->table($table)->strict(false)->insert($data); } - $result = $insertId; } // 新增回调 $this->trigger('after_insert', $this);