mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-10 00:22:48 +08:00
改进Model类的save方法
This commit is contained in:
@@ -263,13 +263,14 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 去除没有更新的字段
|
// 去除没有更新的字段
|
||||||
|
$data = [];
|
||||||
foreach ($this->data as $key => $val) {
|
foreach ($this->data as $key => $val) {
|
||||||
if (!in_array($key, $this->change) && !$this->isPk($key)) {
|
if (in_array($key, $this->change) || $this->isPk($key)) {
|
||||||
unset($this->data[$key]);
|
$data[$key] = $val;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = self::db()->where($where)->update($this->data);
|
$result = self::db()->where($where)->update($data);
|
||||||
|
|
||||||
// 更新回调
|
// 更新回调
|
||||||
$this->trigger('after_update', $this);
|
$this->trigger('after_update', $this);
|
||||||
|
|||||||
Reference in New Issue
Block a user