mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-06 07:02:47 +08:00
改进
This commit is contained in:
@@ -929,18 +929,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 获取有更新的数据
|
// 获取有更新的数据
|
||||||
$data = array_udiff_assoc($this->data, $this->origin, function ($a, $b) {
|
$data = $this->getChangedData();
|
||||||
return is_object($a) || $a != $b ? 1 : 0;
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!empty($this->readonly)) {
|
|
||||||
// 只读字段不允许更新
|
|
||||||
foreach ($this->readonly as $key => $field) {
|
|
||||||
if (isset($data[$field])) {
|
|
||||||
unset($data[$field]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (empty($data) || (count($data) == 1 && is_string($pk) && isset($data[$pk]))) {
|
if (empty($data) || (count($data) == 1 && is_string($pk) && isset($data[$pk]))) {
|
||||||
// 没有更新
|
// 没有更新
|
||||||
@@ -1049,6 +1038,29 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
|||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取变化的数据 并排除只读数据
|
||||||
|
* @access public
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getChangedData()
|
||||||
|
{
|
||||||
|
$data = array_udiff_assoc($this->data, $this->origin, function ($a, $b) {
|
||||||
|
return is_object($a) || $a != $b ? 1 : 0;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!empty($this->readonly)) {
|
||||||
|
// 只读字段不允许更新
|
||||||
|
foreach ($this->readonly as $key => $field) {
|
||||||
|
if (isset($data[$field])) {
|
||||||
|
unset($data[$field]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 保存多个数据到当前数据对象
|
* 保存多个数据到当前数据对象
|
||||||
* @access public
|
* @access public
|
||||||
|
|||||||
Reference in New Issue
Block a user