From f7de00b4018ce25b6a65005c457941a51839140f Mon Sep 17 00:00:00 2001 From: Guilherme Blanco Date: Thu, 24 Apr 2014 05:21:24 +0000 Subject: [PATCH] Finalized fix for scalars and newObjects. --- .../Internal/Hydration/AbstractHydrator.php | 14 +++---- .../ORM/Internal/Hydration/ObjectHydrator.php | 40 ++++--------------- 2 files changed, 15 insertions(+), 39 deletions(-) diff --git a/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php b/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php index a62e107ff..62311c80c 100644 --- a/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php +++ b/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php @@ -347,28 +347,28 @@ abstract class AbstractHydrator continue; } - $fieldName = $cache[$key]['fieldName']; + $fieldName = $cacheKeyInfo['fieldName']; switch (true) { - case (isset($cache[$key]['isScalar'])): + case (isset($cacheKeyInfo['isScalar'])): // WARNING: BC break! We know this is the desired behavior to type convert values, but this // erroneous behavior exists since 2.0 and we're forced to keep compatibility. For 3.0 release, // uncomment these 2 lines of code. - //$type = $cache[$key]['type']; + //$type = $cacheKeyInfo['type']; //$value = $type->convertToPHPValue($value, $this->_platform); $rowData[$fieldName] = $value; break; - case (isset($cache[$key]['isMetaColumn'])): - $dqlAlias = $cache[$key]['dqlAlias']; + case (isset($cacheKeyInfo['isMetaColumn'])): + $dqlAlias = $cacheKeyInfo['dqlAlias']; $rowData[$dqlAlias . '_' . $fieldName] = $value; break; default: - $dqlAlias = $cache[$key]['dqlAlias']; - $type = $cache[$key]['type']; + $dqlAlias = $cacheKeyInfo['dqlAlias']; + $type = $cacheKeyInfo['type']; $value = $type->convertToPHPValue($value, $this->_platform); $rowData[$dqlAlias . '_' . $fieldName] = $value; diff --git a/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php b/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php index 473da1b99..d39e30aaa 100644 --- a/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php +++ b/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php @@ -364,28 +364,6 @@ class ObjectHydrator extends AbstractHydrator // Split the row data into chunks of class data. $rowData = $this->gatherRowData($row, $cache, $id, $nonemptyComponents); - // Extract scalar values. They're appended at the end. - if (isset($rowData['scalars'])) { - $scalars = $rowData['scalars']; - - unset($rowData['scalars']); - - if (empty($rowData)) { - ++$this->resultCounter; - } - } - - // Extract "new" object constructor arguments. They're appended at the end. - if (isset($rowData['newObjects'])) { - $newObjects = $rowData['newObjects']; - - unset($rowData['newObjects']); - - if (empty($rowData)) { - ++$this->resultCounter; - } - } - // Hydrate the data chunks foreach ($rowData['data'] as $dqlAlias => $data) { $entityName = $this->_rsm->aliasMap[$dqlAlias]; @@ -586,29 +564,27 @@ class ObjectHydrator extends AbstractHydrator } // Append scalar values to mixed result sets - if (isset($scalars)) { + if (isset($rowData['scalars'])) { if ( ! isset($resultKey) ) { - if (isset($this->_rsm->indexByMap['scalars'])) { - $resultKey = $row[$this->_rsm->indexByMap['scalars']]; - } else { - $resultKey = $this->resultCounter - 1; - } + $resultKey = (isset($this->_rsm->indexByMap['scalars'])) + ? $row[$this->_rsm->indexByMap['scalars']] + : $this->resultCounter - 1; } - foreach ($scalars as $name => $value) { + foreach ($rowData['scalars'] as $name => $value) { $result[$resultKey][$name] = $value; } } // Append new object to mixed result sets - if (isset($newObjects)) { + if (isset($rowData['newObjects'])) { if ( ! isset($resultKey) ) { $resultKey = $this->resultCounter - 1; } - $count = count($newObjects); + $count = count($rowData['newObjects']); - foreach ($newObjects as $objIndex => $newObject) { + foreach ($rowData['newObjects'] as $objIndex => $newObject) { $class = $newObject['class']; $args = $newObject['args']; $obj = $class->newInstanceArgs($args);