Index: lib/Doctrine/Manager.php =================================================================== --- lib/Doctrine/Manager.php (revision 7689) +++ lib/Doctrine/Manager.php (working copy) @@ -76,6 +76,8 @@ Doctrine_Core::HYDRATE_ON_DEMAND => 'Doctrine_Hydrator_RecordDriver', Doctrine_Core::HYDRATE_ARRAY_HIERARCHY => 'Doctrine_Hydrator_ArrayHierarchyDriver', Doctrine_Core::HYDRATE_RECORD_HIERARCHY => 'Doctrine_Hydrator_RecordHierarchyDriver', + //Fix for: http://www.doctrine-project.org/jira/browse/DC-701 + Doctrine_Core::HYDRATE_ARRAY_SHALLOW => 'Doctrine_Hydrator_ArrayShallowDriver', ); protected $_connectionDrivers = array( Index: lib/Doctrine/Core.php =================================================================== --- lib/Doctrine/Core.php (revision 7689) +++ lib/Doctrine/Core.php (working copy) @@ -372,7 +372,13 @@ * HYDRATE_RECORD_HIERARCHY */ const HYDRATE_RECORD_HIERARCHY = 9; - + + //Fix For: http://www.doctrine-project.org/jira/browse/DC-701 + /** + * HYDRATE_ARRAY_SHALLOW + */ + const HYDRATE_ARRAY_SHALLOW = 10; + /** * VALIDATION CONSTANTS */ Index: lib/Doctrine/Hydrator/ArrayShallowDriver.php =================================================================== --- lib/Doctrine/Hydrator/ArrayShallowDriver.php (revision 0) +++ lib/Doctrine/Hydrator/ArrayShallowDriver.php (revision 0) @@ -0,0 +1,47 @@ +. + */ + +/** + * Extended version of Doctrine_Hydrator_ScalarDriver, passes its _gatherRowData function a value of false for $aliasPrefix in order to cause it to generate the sorts of array keys one would see in a HYDRATE_ARRAY type return. + * Note: This hydrator will have issues with fields in the return that have the same name (such as 2 fields each called id) -- the second field value will overwrite the first field. + * @package Doctrine + * @subpackage Hydrate + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL + * @link www.doctrine-project.org + * @since 1.2.3 + * @version $Revision$ + * @author Will Ferrer + */ +class Doctrine_Hydrator_ArrayShallowDriver extends Doctrine_Hydrator_ScalarDriver +{ + + public function hydrateResultSet($stmt) + { + $cache = array(); + $result = array(); + while ($data = $stmt->fetch(Doctrine_Core::FETCH_ASSOC)) { + $result[] = $this->_gatherRowData($data, $cache, false); + } + + return $result; + } + +} Index: tests/Hydrate/ScalarTestCase.php =================================================================== --- tests/Hydrate/ScalarTestCase.php (revision 7689) +++ tests/Hydrate/ScalarTestCase.php (working copy) @@ -153,4 +153,93 @@ $q->free(); } + // Fix for: http://www.doctrine-project.org/jira/browse/DC-701 + public function testHydrateArrayShallowWithJoin() + { + $q = Doctrine_Query::create(); + $q->select("u.*, p.id as phonenumber_id, p.phonenumber, p.entity_id") + ->from("User u") + ->innerJoin("u.Phonenumber p"); + + $res = $q->execute(array(), Doctrine_Core::HYDRATE_ARRAY_SHALLOW); + + $this->assertTrue(is_array($res)); + $this->assertEqual(2, count($res)); + //row1 + $this->assertEqual(1, $res[0]['id']); + $this->assertEqual('romanb', $res[0]['name']); + $this->assertEqual(null, $res[0]['loginname']); + $this->assertEqual(null, $res[0]['password']); + $this->assertEqual(0, $res[0]['type']); + $this->assertEqual(null, $res[0]['created']); + $this->assertEqual(null, $res[0]['updated']); + $this->assertEqual(null, $res[0]['email_id']); + $this->assertEqual(1, $res[0]['phonenumber_id']); + $this->assertEqual(112, $res[0]['phonenumber']); + $this->assertEqual(1, $res[0]['entity_id']); + //row2 + $this->assertEqual(1, $res[1]['id']); + $this->assertEqual('romanb', $res[1]['name']); + $this->assertEqual(null, $res[1]['loginname']); + $this->assertEqual(null, $res[1]['password']); + $this->assertEqual(0, $res[1]['type']); + $this->assertEqual(null, $res[1]['created']); + $this->assertEqual(null, $res[1]['updated']); + $this->assertEqual(null, $res[1]['email_id']); + $this->assertEqual(2, $res[1]['phonenumber_id']); + $this->assertEqual(110, $res[1]['phonenumber']); + $this->assertEqual(1, $res[1]['entity_id']); + + $q->free(); + } + // Fix for: http://www.doctrine-project.org/jira/browse/DC-701 + public function testHydrateArrayShallow() + { + $q = Doctrine_Query::create(); + $q->select("u.*")->from("User u"); + + $res = $q->execute(array(), Doctrine_Core::HYDRATE_ARRAY_SHALLOW); + + $this->assertTrue(is_array($res)); + $this->assertEqual(1, count($res)); + //row1 + $this->assertEqual(1, $res[0]['id']); + $this->assertEqual('romanb', $res[0]['name']); + $this->assertEqual(null, $res[0]['loginname']); + $this->assertEqual(null, $res[0]['password']); + $this->assertEqual(0, $res[0]['type']); + $this->assertEqual(null, $res[0]['created']); + $this->assertEqual(null, $res[0]['updated']); + $this->assertEqual(null, $res[0]['email_id']); + + $q->free(); + } + // Fix for: http://www.doctrine-project.org/jira/browse/DC-701 + public function testHydrateArrayShallowWithJoinAndAggregate() + { + $q = Doctrine_Query::create(); + $q->select("u.id, UPPER(u.name) nameUpper, p.id as phonenumber_id, p.phonenumber, p.entity_id") + ->from("User u") + ->innerJoin("u.Phonenumber p"); + + $res = $q->execute(array(), Doctrine_Core::HYDRATE_ARRAY_SHALLOW); + + $this->assertTrue(is_array($res)); + $this->assertEqual(2, count($res)); + + //row1 + $this->assertEqual(1, $res[0]['id']); + $this->assertEqual('ROMANB', $res[0]['nameUpper']); + $this->assertEqual(1, $res[0]['id']); + $this->assertEqual(112, $res[0]['phonenumber']); + $this->assertEqual(1, $res[0]['entity_id']); + //row2 + $this->assertEqual(1, $res[1]['id']); + $this->assertEqual('ROMANB', $res[1]['nameUpper']); + $this->assertEqual(2, $res[1]['phonenumber_id']); + $this->assertEqual(110, $res[1]['phonenumber']); + $this->assertEqual(1, $res[1]['entity_id']); + + $q->free(); + } } \ No newline at end of file