Skip to content

Commit 862763e

Browse files
committed
改进save方法
1 parent 5880cef commit 862763e

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/Entity.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -826,12 +826,22 @@ public function save(array | object $data = [], $where = []): bool
826826

827827
$model = $this->model();
828828
if ($model instanceof Model) {
829-
$result = $model->allowField($allow)->setUpdateWhere($where)->save($data);
829+
if(!empty($where)) {
830+
$model->setUpdateWhere($where);
831+
} else {
832+
$model->setKey($this->getKey());
833+
}
834+
$result = $model->allowField($allow)->save($data);
830835
if (false === $result) {
831836
return false;
832837
}
833838
} else {
834-
$result = $model->field($allow)->where($where)->save($data, !$isUpdate);
839+
if(!empty($where)) {
840+
$model->where($where);
841+
} else {
842+
$model->setKey($this->getKey());
843+
}
844+
$result = $model->field($allow)->save($data, !$isUpdate);
835845
if (!$isUpdate) {
836846
$this->setKey($model->getLastInsID());
837847
}

0 commit comments

Comments
 (0)