mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-01 20:52:48 +08:00
改进Model类的save方法 新增数据的时候添加不是自增主键的处理
This commit is contained in:
@@ -649,7 +649,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
||||
if (false === $this->trigger('before_write', $this)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$pk = $this->getPk();
|
||||
if ($this->isUpdate) {
|
||||
// 自动更新
|
||||
$this->autoCompleteData($this->update);
|
||||
@@ -680,7 +680,6 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
||||
$where = $this->updateWhere;
|
||||
}
|
||||
|
||||
$pk = $this->getPk();
|
||||
if (is_string($pk) && isset($data[$pk])) {
|
||||
if (!isset($where[$pk])) {
|
||||
unset($where);
|
||||
@@ -710,10 +709,9 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
||||
$result = $this->db()->insert($this->data);
|
||||
|
||||
// 获取自动增长主键
|
||||
if ($result) {
|
||||
if ($result && is_string($pk) && !isset($this->data[$pk])) {
|
||||
$insertId = $this->db()->getLastInsID($sequence);
|
||||
$pk = $this->getPk();
|
||||
if (is_string($pk) && $insertId) {
|
||||
if ($insertId) {
|
||||
$this->data[$pk] = $insertId;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user