Skip to content

Commit

Permalink
改进模型新增的主键获取
Browse files Browse the repository at this point in the history
  • Loading branch information
liu21st committed Nov 17, 2019
1 parent 3fb17fa commit ff5f112
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -645,14 +645,15 @@ protected function insertData(string $sequence = null): bool
$result = $db->strict(false)
->field($allowFields)
->replace($this->replace)
->insert($this->data, false, $sequence);
->sequence($sequence)
->insert($this->data, true);

// 获取自动增长主键
if ($result && $insertId = $db->getLastInsID($sequence)) {
if ($result) {
$pk = $this->getPk();

if (is_string($pk) && (!isset($this->data[$pk]) || '' == $this->data[$pk])) {
$this->data[$pk] = $insertId;
$this->data[$pk] = $result;
}
}

Expand Down

0 comments on commit ff5f112

Please sign in to comment.