mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-07 23:22:48 +08:00
修正Driver当写入空数据的问题
This commit is contained in:
@@ -286,12 +286,10 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
|||||||
if (false === $this->trigger('before_update', $this)) {
|
if (false === $this->trigger('before_update', $this)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// 更新的时候检测字段更改
|
// 去除没有更新的字段
|
||||||
if (!empty($this->change)) {
|
foreach ($data as $key => $val) {
|
||||||
foreach ($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) && !isset($this->relation[$key])) {
|
unset($data[$key]);
|
||||||
unset($data[$key]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1350,6 +1350,9 @@ abstract class Driver
|
|||||||
*/
|
*/
|
||||||
protected function parseData($data, $bind)
|
protected function parseData($data, $bind)
|
||||||
{
|
{
|
||||||
|
if (empty($data)) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
$fields = array_keys($bind);
|
$fields = array_keys($bind);
|
||||||
foreach ($data as $key => $val) {
|
foreach ($data as $key => $val) {
|
||||||
if (!in_array($key, $fields, true)) {
|
if (!in_array($key, $fields, true)) {
|
||||||
@@ -1761,7 +1764,10 @@ abstract class Driver
|
|||||||
$options = $this->_parseOptions();
|
$options = $this->_parseOptions();
|
||||||
$bind = $this->getTableInfo($options['table'], 'bind');
|
$bind = $this->getTableInfo($options['table'], 'bind');
|
||||||
|
|
||||||
$data = $this->parseData($data, $bind);
|
$data = $this->parseData($data, $bind);
|
||||||
|
if (empty($data)) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
$fields = array_keys($data);
|
$fields = array_keys($data);
|
||||||
$values = array_values($data);
|
$values = array_values($data);
|
||||||
// 兼容数字传入方式
|
// 兼容数字传入方式
|
||||||
@@ -1854,7 +1860,9 @@ abstract class Driver
|
|||||||
$bind = $this->getTableInfo($options['table'], 'bind');
|
$bind = $this->getTableInfo($options['table'], 'bind');
|
||||||
$table = $this->parseTable($options['table']);
|
$table = $this->parseTable($options['table']);
|
||||||
$data = $this->parseData($data, $bind);
|
$data = $this->parseData($data, $bind);
|
||||||
|
if (empty($data)) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
foreach ($data as $key => $val) {
|
foreach ($data as $key => $val) {
|
||||||
$set[] = $key . '=' . $val;
|
$set[] = $key . '=' . $val;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user