diff --git a/lib/Doctrine/ORM/Internal/Hydration/SimpleObjectHydrator.php b/lib/Doctrine/ORM/Internal/Hydration/SimpleObjectHydrator.php index a7ca1b92665..ec5eef1ac53 100644 --- a/lib/Doctrine/ORM/Internal/Hydration/SimpleObjectHydrator.php +++ b/lib/Doctrine/ORM/Internal/Hydration/SimpleObjectHydrator.php @@ -138,7 +138,7 @@ protected function hydrateRowData(array $sqlResult, array &$result) // Prevent overwrite in case of inherit classes using same property name (See AbstractHydrator) if ( ! isset($data[$fieldName]) || ! $valueIsNull) { // If we have inheritance in resultset, make sure the field belongs to the correct class - if (isset($cacheKeyInfo['discriminatorValues']) && ! in_array($discrColumnValue, $cacheKeyInfo['discriminatorValues'], true)) { + if (isset($cacheKeyInfo['discriminatorValues']) && ! in_array((string) $discrColumnValue, $cacheKeyInfo['discriminatorValues'], true)) { continue; } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH8055Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH8055Test.php new file mode 100644 index 00000000000..cb48fac4f88 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH8055Test.php @@ -0,0 +1,71 @@ +setUpEntitySchema([ + GH8055BaseClass::class, + GH8055SubClass::class, + ]); + } + + public function testNumericDescriminatorColumn() : void + { + $entity = new GH8055SubClass(); + $entity->value = 'test'; + $this->_em->persist($entity); + $this->_em->flush(); + $this->_em->clear(); + + $repository = $this->_em->getRepository(GH8055SubClass::class); + $hydrated = $repository->find($entity->id); + + self::assertSame('test', $hydrated->value); + } +} + +/** + * @Entity() + * @Table(name="gh8055") + * @InheritanceType("JOINED") + * @DiscriminatorColumn(name="discr", type="integer") + * @DiscriminatorMap({ + * "1" = GH8055BaseClass::class, + * "2" = GH8055SubClass::class + * }) + */ +class GH8055BaseClass +{ + /** + * @Id @GeneratedValue + * @Column(type="integer") + */ + public $id; +} + +/** + * @Entity() + */ +class GH8055SubClass extends GH8055BaseClass +{ + /** + * @Column(name="test", type="string") + * @var string + */ + public $value; +}