Skip to content

Commit

Permalink
Merge branch 'top-think:3.0' into 3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
axguowen committed Apr 28, 2024
2 parents fecae0a + e35f497 commit f0621ab
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/db/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ protected function parseData(Query $query, array $data = [], array $fields = [],
if ($val instanceof Raw) {
$result[$item] = $this->parseRaw($query, $val);
continue;
}elseif (is_null($val)) {
// json字段默认为NULL,需要优先处理,不然会出现json字段写入字符串null的情况
$result[$item] = 'NULL';
continue;
} elseif (!is_scalar($val) && (in_array($key, (array) $query->getOptions('json')) || 'json' == $query->getFieldType($key))) {
$val = json_encode($val);
}
Expand All @@ -76,8 +80,6 @@ protected function parseData(Query $query, array $data = [], array $fields = [],
if ($options['strict']) {
throw new Exception('fields not exists:[' . $key . ']');
}
} elseif (is_null($val)) {
$result[$item] = 'NULL';
} elseif (is_array($val) && !empty($val) && is_string($val[0])) {
if (in_array(strtoupper($val[0]), ['INC', 'DEC'])) {
$result[$item] = match (strtoupper($val[0])) {
Expand Down
3 changes: 2 additions & 1 deletion src/model/concern/Attribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Stringable;
use think\db\Raw;
use think\helper\Str;
use think\Model;
use think\model\Relation;

/**
Expand Down Expand Up @@ -234,7 +235,7 @@ public function data(array|object $data, bool $set = false, array $allow = [])
} elseif (is_object($data)) {
$data = get_object_vars($data);
}

// 清空数据
$this->data = [];

Expand Down

0 comments on commit f0621ab

Please sign in to comment.