Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix regression in 2.7.1 when mysqli is used with discriminator column that is not a string #8055

Merged
merged 3 commits into from Mar 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -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;
}

Expand Down
71 changes: 71 additions & 0 deletions tests/Doctrine/Tests/ORM/Functional/Ticket/GH8055Test.php
@@ -0,0 +1,71 @@
<?php

declare(strict_types=1);

namespace Doctrine\Tests\ORM\Functional\Ticket;

use Doctrine\Tests\OrmFunctionalTestCase;

/**
* @group GH8055
*/
final class GH8055Test extends OrmFunctionalTestCase
{
/**
* {@inheritDoc}
*/
protected function setUp() : void
{
parent::setUp();

$this->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;
}