mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-07 23:22:48 +08:00
改进save方法
This commit is contained in:
@@ -952,6 +952,12 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
|||||||
}
|
}
|
||||||
$pk = $this->getPk();
|
$pk = $this->getPk();
|
||||||
if ($this->isUpdate) {
|
if ($this->isUpdate) {
|
||||||
|
// 获取有更新的数据
|
||||||
|
$data = $this->getChangedData();
|
||||||
|
|
||||||
|
// 检测字段
|
||||||
|
$this->checkAllowField($data);
|
||||||
|
|
||||||
// 自动更新
|
// 自动更新
|
||||||
$this->autoCompleteData($this->update);
|
$this->autoCompleteData($this->update);
|
||||||
|
|
||||||
@@ -960,9 +966,6 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取有更新的数据
|
|
||||||
$data = $this->getChangedData();
|
|
||||||
|
|
||||||
if (empty($data) || (count($data) == 1 && is_string($pk) && isset($data[$pk]))) {
|
if (empty($data) || (count($data) == 1 && is_string($pk) && isset($data[$pk]))) {
|
||||||
// 关联更新
|
// 关联更新
|
||||||
if (isset($relation)) {
|
if (isset($relation)) {
|
||||||
@@ -978,9 +981,6 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
|||||||
$where = $this->updateWhere;
|
$where = $this->updateWhere;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检测字段
|
|
||||||
$this->checkAllowField($data);
|
|
||||||
|
|
||||||
// 保留主键数据
|
// 保留主键数据
|
||||||
foreach ($this->data as $key => $val) {
|
foreach ($this->data as $key => $val) {
|
||||||
if ($this->isPk($key)) {
|
if ($this->isPk($key)) {
|
||||||
@@ -1008,8 +1008,12 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
|||||||
$this->trigger('after_update', $this);
|
$this->trigger('after_update', $this);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
// 检测字段
|
||||||
|
$this->checkAllowField($this->data);
|
||||||
|
|
||||||
// 自动写入
|
// 自动写入
|
||||||
$this->autoCompleteData($this->insert);
|
$this->autoCompleteData($this->insert);
|
||||||
|
|
||||||
// 自动写入创建时间和更新时间
|
// 自动写入创建时间和更新时间
|
||||||
if ($this->autoWriteTimestamp) {
|
if ($this->autoWriteTimestamp) {
|
||||||
if ($this->createTime && !isset($this->data[$this->createTime])) {
|
if ($this->createTime && !isset($this->data[$this->createTime])) {
|
||||||
@@ -1024,9 +1028,6 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检测字段
|
|
||||||
$this->checkAllowField($this->data);
|
|
||||||
|
|
||||||
$result = $this->getQuery()->insert($this->data);
|
$result = $this->getQuery()->insert($this->data);
|
||||||
|
|
||||||
// 获取自动增长主键
|
// 获取自动增长主键
|
||||||
|
|||||||
Reference in New Issue
Block a user