Skip to content

Commit c65ff66

Browse files
committed
Merge branch '2.13.x-enum-arrayhydration' into 2.13.x
* 2.13.x-enum-arrayhydration: Fix ArrayHydration of enums
2 parents 5f29fcd + bc7e252 commit c65ff66

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php

+5
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,10 @@ protected function gatherRowData(array $data, array &$id, array &$nonemptyCompon
464464
break;
465465
}
466466

467+
if ($value !== null && isset($cacheKeyInfo['enumType'])) {
468+
$value = $this->buildEnum($value, $cacheKeyInfo['enumType']);
469+
}
470+
467471
$rowData['data'][$dqlAlias][$fieldName] = $type
468472
? $type->convertToPHPValue($value, $this->_platform)
469473
: $value;
@@ -547,6 +551,7 @@ protected function hydrateColumnInfo($key)
547551
'fieldName' => $fieldName,
548552
'type' => Type::getType($fieldMapping['type']),
549553
'dqlAlias' => $ownerMap,
554+
'enumType' => $this->_rsm->enumMappings[$key] ?? null,
550555
];
551556

552557
// the current discriminator value must be saved in order to disambiguate fields hydration,

lib/Doctrine/ORM/Query/SqlWalker.php

+4
Original file line numberDiff line numberDiff line change
@@ -1520,6 +1520,10 @@ public function walkSelectExpression($selectExpression)
15201520
$this->scalarResultAliasMap[$resultAlias][] = $columnAlias;
15211521

15221522
$this->rsm->addFieldResult($dqlAlias, $columnAlias, $fieldName, $class->name);
1523+
1524+
if (! empty($mapping['enumType'])) {
1525+
$this->rsm->addEnumResult($columnAlias, $mapping['enumType']);
1526+
}
15231527
}
15241528

15251529
// Add any additional fields of subclasses (excluding inherited fields)

tests/Doctrine/Tests/ORM/Functional/EnumTest.php

+23
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Doctrine\Tests\ORM\Functional;
66

7+
use Doctrine\ORM\AbstractQuery;
78
use Doctrine\ORM\Mapping\Column;
89
use Doctrine\ORM\Mapping\Driver\AttributeDriver;
910
use Doctrine\ORM\Mapping\MappingException;
@@ -86,6 +87,28 @@ public function testEnumHydration(): void
8687
$this->assertEquals(Suit::Clubs, $result[0]['suit']);
8788
}
8889

90+
public function testEnumHydrationArrayHydrator(): void
91+
{
92+
$this->setUpEntitySchema([Card::class, CardWithNullable::class]);
93+
94+
$card = new Card();
95+
$card->suit = Suit::Clubs;
96+
97+
$this->_em->persist($card);
98+
$this->_em->flush();
99+
$this->_em->clear();
100+
101+
$result = $this->_em->createQueryBuilder()
102+
->from(Card::class, 'c')
103+
->select('c')
104+
->getQuery()
105+
//->getResult();
106+
->getResult(AbstractQuery::HYDRATE_ARRAY);
107+
108+
$this->assertInstanceOf(Suit::class, $result[0]['suit']);
109+
$this->assertEquals(Suit::Clubs, $result[0]['suit']);
110+
}
111+
89112
public function testNullableEnumHydration(): void
90113
{
91114
$this->setUpEntitySchema([Card::class, CardWithNullable::class]);

0 commit comments

Comments
 (0)