Skip to content

Commit

Permalink
Fix SQL alias generation regression for simple inheritance (#8329)
Browse files Browse the repository at this point in the history
This fixes a regression from 099c5b4.
Without the fix, "where part" in SQL is generated with incorrect aliases.
See #8229 (comment).
  • Loading branch information
rogregoire authored Nov 10, 2020
1 parent 385b5a2 commit f4ebded
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1698,7 +1698,7 @@ private function getSelectConditionStatementColumnSQL($field, $assoc = null)
if (isset($this->class->fieldMappings[$field])) {
// Fix for bug GH-8229 (id column from parent class renamed in child class):
// Use the correct metadata and name for the id column
if (isset($this->class->fieldMappings[$field]['inherited'])) {
if (isset($this->class->fieldMappings[$field]['inherited']) && $this->class->inheritanceType !== ClassMetadata::INHERITANCE_TYPE_NONE) {
$className = $this->class->fieldMappings[$field]['inherited'];
$class = $this->em->getClassMetadata($className);
} else {
Expand Down
41 changes: 41 additions & 0 deletions tests/Doctrine/Tests/ORM/Functional/Ticket/GH8229Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ protected function setUp() : void
[
GH8229Resource::class,
GH8229User::class,
GH8229EntityWithoutDiscriminator::class,
EntityExtendingGH8229EntityWithoutDiscriminator::class,
]
);
}
Expand Down Expand Up @@ -183,6 +185,19 @@ public function testCorrectColumnNamesInPessimisticWriteLock()

self::assertEquals($identifier, $entity->id);
}

/** this test check alias generation not altered by inheritance in ResolvedTargetEntities mapped classes
*/
public function testBasicEntityPersisterAliasGenerationWithSimpleInheritance()
{
$this->expectNotToPerformAssertions();

$entity = new EntityExtendingGH8229EntityWithoutDiscriminator();
$this->_em->persist($entity);
$this->_em->flush();

$this->_em->getRepository(EntityExtendingGH8229EntityWithoutDiscriminator::class)->findOneBy(['id' => $entity->getId()]);
}
}


Expand Down Expand Up @@ -244,3 +259,29 @@ public function __construct($username)
$this->username = $username;
}
}

/**
* @Entity
* @Table(name="gh8229_replacedentity")
*/
class GH8229EntityWithoutDiscriminator
{
/**
* @Id
* @GeneratedValue
* @Column(type="integer")
*/
public $id;

public function getId()
{
return $this->id;
}
}

/**
* @Entity
*/
final class EntityExtendingGH8229EntityWithoutDiscriminator extends GH8229EntityWithoutDiscriminator
{
}

0 comments on commit f4ebded

Please sign in to comment.