mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-08 23:52:49 +08:00
model改进
This commit is contained in:
@@ -337,24 +337,26 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
|||||||
if (!$this->validateData()) {
|
if (!$this->validateData()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (false === $this->trigger('before_write', $this)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
// 数据自动完成
|
// 数据自动完成
|
||||||
$this->autoCompleteData($this->auto);
|
$this->autoCompleteData($this->auto);
|
||||||
|
|
||||||
|
// 事件回调
|
||||||
|
if (false === $this->trigger('before_write', $this)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if ($this->isUpdate) {
|
if ($this->isUpdate) {
|
||||||
// 更新数据
|
|
||||||
// 自动更新
|
// 自动更新
|
||||||
$this->autoCompleteData($this->update);
|
$this->autoCompleteData($this->update);
|
||||||
|
// 事件回调
|
||||||
if (false === $this->trigger('before_update', $this)) {
|
if (false === $this->trigger('before_update', $this)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 去除没有更新的字段
|
// 去除没有更新的字段
|
||||||
foreach ($this->data as $key => $val) {
|
foreach ($this->data as $key => $val) {
|
||||||
if (!in_array($key, $this->change) && !$this->isPk($key) && !isset($this->relation[$key])) {
|
if (!in_array($key, $this->change) && !$this->isPk($key)) {
|
||||||
unset($this->data[$key]);
|
unset($this->data[$key]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -368,7 +370,6 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
|||||||
// 更新回调
|
// 更新回调
|
||||||
$this->trigger('after_update', $this);
|
$this->trigger('after_update', $this);
|
||||||
} else {
|
} else {
|
||||||
// 新增数据
|
|
||||||
// 自动写入
|
// 自动写入
|
||||||
$this->autoCompleteData($this->insert);
|
$this->autoCompleteData($this->insert);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user