改进model类的save方法的复合主键包含自增的情况

This commit is contained in:
thinkphp
2017-12-27 21:19:52 +08:00
parent c01a108a52
commit 97f82a1a9d

View File

@@ -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;
}
}
}