mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-01 12:42:48 +08:00
改进Model类的save方法 修正Merge类的save方法支持 where参数更新
This commit is contained in:
@@ -586,7 +586,8 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
||||
}
|
||||
|
||||
$result = $this->db()->where($where)->update($data);
|
||||
|
||||
// 清空change
|
||||
$this->change = [];
|
||||
// 更新回调
|
||||
$this->trigger('after_update', $this);
|
||||
} else {
|
||||
@@ -613,16 +614,14 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
||||
}
|
||||
$result = $insertId;
|
||||
}
|
||||
// 标记为更新
|
||||
$this->isUpdate = true;
|
||||
// 新增回调
|
||||
$this->trigger('after_insert', $this);
|
||||
}
|
||||
// 写入回调
|
||||
$this->trigger('after_write', $this);
|
||||
|
||||
// 标记为更新
|
||||
$this->isUpdate = true;
|
||||
// 清空change
|
||||
$this->change = [];
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
@@ -183,10 +183,21 @@ class Merge extends Model
|
||||
return false;
|
||||
}
|
||||
|
||||
if (empty($where) && !empty($this->updateWhere)) {
|
||||
$where = $this->updateWhere;
|
||||
}
|
||||
|
||||
if (!empty($where)) {
|
||||
$pk = $this->getPk();
|
||||
if (is_string($pk) && isset($data[$pk])) {
|
||||
unset($data[$pk]);
|
||||
}
|
||||
}
|
||||
|
||||
// 处理模型数据
|
||||
$data = $this->parseData($this->name, $this->data);
|
||||
// 写入主表数据
|
||||
$result = $db->strict(false)->update($data);
|
||||
$result = $db->strict(false)->where($where)->update($data);
|
||||
|
||||
// 写入附表数据
|
||||
foreach (static::$relationModel as $key => $model) {
|
||||
|
||||
Reference in New Issue
Block a user