diff --git a/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php b/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php index 6152c4176..2797a76e9 100644 --- a/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php +++ b/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php @@ -451,9 +451,14 @@ class BasicEntityPersister implements EntityPersister continue; } - $params[] = $identifier[$idField]; - $where[] = $this->class->associationMappings[$idField]['joinColumns'][0]['name']; - $targetMapping = $this->em->getClassMetadata($this->class->associationMappings[$idField]['targetEntity']); + $params[] = $identifier[$idField]; + $where[] = $this->quoteStrategy->getJoinColumnName( + $this->class->associationMappings[$idField]['joinColumns'][0], + $this->class, + $this->platform + ); + + $targetMapping = $this->em->getClassMetadata($this->class->associationMappings[$idField]['targetEntity']); switch (true) { case (isset($targetMapping->fieldMappings[$targetMapping->identifier[0]])): diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7012Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7012Test.php new file mode 100644 index 000000000..38f57c57c --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7012Test.php @@ -0,0 +1,82 @@ +useModelSet('quote'); + + parent::setUp(); + + $this->setUpEntitySchema([GH7012UserData::class]); + } + + /** + * @group 7012 + */ + public function testUpdateEntityWithIdentifierAssociationWithQuotedJoinColumn() : void + { + $user = new QuotedUser(); + $user->name = 'John Doe'; + + $this->_em->persist($user); + $this->_em->flush(); + + $userData = new GH7012UserData($user, '123456789'); + + $this->_em->persist($userData); + $this->_em->flush(); + + $userData->name = '4321'; + $this->_em->flush(); + + $platform = $this->_em->getConnection()->getDatabasePlatform(); + $quotedTableName = $platform->quoteIdentifier('quote-user-data'); + $quotedColumn = $platform->quoteIdentifier('name'); + $quotedIdentifier = $platform->quoteIdentifier('user-id'); + + self::assertNotEquals('quote-user-data', $quotedTableName); + self::assertNotEquals('name', $quotedColumn); + self::assertNotEquals('user-id', $quotedIdentifier); + + $queries = $this->_sqlLoggerStack->queries; + + $this->assertSQLEquals( + sprintf('UPDATE %s SET %s = ? WHERE %s = ?', $quotedTableName, $quotedColumn, $quotedIdentifier), + $queries[$this->_sqlLoggerStack->currentQuery - 1]['sql'] + ); + } +} + + +/** + * @Entity + * @Table(name="`quote-user-data`") + */ +class GH7012UserData +{ + /** + * @Id + * @OneToOne(targetEntity=Doctrine\Tests\Models\Quote\User::class) + * @JoinColumn(name="`user-id`", referencedColumnName="`user-id`", onDelete="CASCADE") + */ + public $user; + + /** + * @Column(type="string", name="`name`") + */ + public $name; + + public function __construct(QuotedUser $user, string $name) + { + $this->user = $user; + $this->name = $name; + } +}