From 8a6659cdd2f50a147666bf6b81d5530377d92500 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Thu, 14 Sep 2017 11:05:25 +0200 Subject: [PATCH] set empty result set as null --- DataStorage/Database/DataMapperAbstract.php | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/DataStorage/Database/DataMapperAbstract.php b/DataStorage/Database/DataMapperAbstract.php index 8e9dfbc11..ecbcc601d 100644 --- a/DataStorage/Database/DataMapperAbstract.php +++ b/DataStorage/Database/DataMapperAbstract.php @@ -1703,7 +1703,7 @@ class DataMapperAbstract implements DataMapperInterface } else { $value = $mapper::get($reflectionProperty->getValue($obj)); } - + $reflectionProperty->setValue($obj, $value); if (!$accessible) { @@ -1765,10 +1765,10 @@ class DataMapperAbstract implements DataMapperInterface } if (in_array(static::$columns[$column]['type'], ['string', 'int', 'float', 'bool'])) { - if($reflectionProperty->getValue($obj) !== null) { + if($reflectionProperty->getValue($obj) !== null || $value !== null) { settype($value, static::$columns[$column]['type']); } - + $reflectionProperty->setValue($obj, $value); } elseif (static::$columns[$column]['type'] === 'DateTime') { $reflectionProperty->setValue($obj, new \DateTime($value ?? '')); @@ -1872,7 +1872,15 @@ class DataMapperAbstract implements DataMapperInterface self::fillRelations($obj, $relations); self::clear(); - return count($obj) === 1 ? reset($obj) : $obj; + $countResulsts = count($obj); + + if($countResulsts === 0) { + return null; + } elseif($countResulsts === 1) { + return reset($obj); + } + + return $obj; } /**