Skip to content

Commit

Permalink
Merge pull request #14 from q495265366/patch-3
Browse files Browse the repository at this point in the history
实体类查询的时候不支持字段为string然后NULL类型,查询的时候出现缺失字段
  • Loading branch information
stelin committed Apr 22, 2018
2 parents 270f2e8 + 1a941eb commit bf82860
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/db/src/Helper/EntityHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Swoft\Db\Bean\Collector\EntityCollector;
use Swoft\Db\Exception\DbException;
use Swoft\Db\Types;
use Swoft\Helper\StringHelper;

/**
* EntityHelper
Expand Down Expand Up @@ -55,17 +56,18 @@ public static function arrayToEntity(array $data, string $className)
}

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

$setterMethod = StringHelper::camel('set_' . $field);
$type = $entities[$className]['field'][$field]['type'];
$value = self::trasferTypes($type, $value);

if (method_exists($object, $setterMethod)) {
if (\method_exists($object, $setterMethod)) {
$attrs[$col] = $value;

$object->$setterMethod($value);
}
}
if (method_exists($object, 'setAttrs')) {
if (\method_exists($object, 'setAttrs')) {
$object->setAttrs($attrs);
}

Expand All @@ -83,7 +85,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 = null === $value ? null : (string)$value;
} elseif ($type === Types::BOOLEAN) {
$value = (bool)$value;
} elseif ($type === Types::FLOAT) {
Expand Down Expand Up @@ -124,7 +126,7 @@ public static function transferParameter($key, $value, $type): array
*/
private static function formatParamsKey($key): string
{
if (\is_string($key) && strpos($key, ':') === false) {
if (\is_string($key) && \strpos($key, ':') === false) {
return ':' . $key;
}

Expand Down

0 comments on commit bf82860

Please sign in to comment.