Skip to content

Commit

Permalink
实体类查询的时候不支持字段为string然后NULL类型,查询的时候出现缺失字段
Browse files Browse the repository at this point in the history
  • Loading branch information
wfuren committed Apr 20, 2018
1 parent 4fb2711 commit 22cec29
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/Helper/EntityHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,12 @@ public static function arrayToEntity(array $data, string $className)
}

$field = $entities[$className]['column'][$col];
$setterMethod = 'set' . ucfirst($field);

$function = explode('_', $field);
$function = array_map(function ($word) {
return ucfirst($word);
}, $function);
$setterMethod = 'set' . implode('', $function);

$type = $entities[$className]['field'][$field]['type'];
$value = self::trasferTypes($type, $value);

Expand All @@ -83,7 +87,7 @@ public static function trasferTypes($type, $value)
if ($type === Types::INT || $type === Types::NUMBER) {
$value = (int)$value;
} elseif ($type === Types::STRING) {
$value = (string)$value;
$value = is_null($value) ? (unset)$value : (string)$value;
} elseif ($type === Types::BOOLEAN) {
$value = (bool)$value;
} elseif ($type === Types::FLOAT) {
Expand Down

0 comments on commit 22cec29

Please sign in to comment.