Skip to content

Commit

Permalink
[GH-6394] Bugfix: IdentifierFlattener support for association non-obj…
Browse files Browse the repository at this point in the history
…ect values. (#8384)

* [GH-6394] Bugfix: IdentifierFlattener support for association non-object values

* [GH-6394] Bugfix: BasicEntityPersister::update used wrong identifiers for version assignment.

* Exclude MissingNativeTypeHint phpcs rule as 7.4 is not lowest version.
  • Loading branch information
beberlei committed Apr 1, 2021
1 parent 0b25d4d commit 657a30f
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 1 deletion.
Expand Up @@ -400,7 +400,7 @@ public function update($entity)
$this->updateTable($entity, $quotedTableName, $data, $isVersioned);

if ($isVersioned) {
$id = $this->em->getUnitOfWork()->getEntityIdentifier($entity);
$id = $this->class->getIdentifierValues($entity);

$this->assignDefaultVersionValue($entity, $id);
}
Expand Down
1 change: 1 addition & 0 deletions phpcs.xml.dist
Expand Up @@ -22,6 +22,7 @@
<exclude name="SlevomatCodingStandard.TypeHints.DeclareStrictTypes"/>
<exclude name="SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingAnyTypeHint" />
<exclude name="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingReturnTypeHint"/>
<exclude name="SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingNativeTypeHint" />
<exclude name="SlevomatCodingStandard.Exceptions.ReferenceThrowableOnly.ReferencedGeneralException"/>
<exclude name="SlevomatCodingStandard.ControlStructures.EarlyExit"/>
<exclude name="SlevomatCodingStandard.Classes.SuperfluousAbstractClassNaming"/>
Expand Down
103 changes: 103 additions & 0 deletions tests/Doctrine/Tests/ORM/Functional/Ticket/GH6394Test.php
@@ -0,0 +1,103 @@
<?php

declare(strict_types=1);

namespace Doctrine\Tests\ORM\Functional\Ticket;

use Doctrine\Tests\OrmFunctionalTestCase;

class GH6394Test extends OrmFunctionalTestCase
{
protected function setUp(): void
{
parent::setUp();

$this->_schemaTool->createSchema(
[
$this->_em->getClassMetadata(A::class),
$this->_em->getClassMetadata(B::class),
]
);
}

/**
* Test the the version of an entity can be fetched, when the id field and
* the id column are different.
*
* @group 6393
*/
public function testFetchVersionValueForDifferentIdFieldAndColumn(): void
{
$a = new A(1);
$this->_em->persist($a);

$b = new B($a, 'foo');
$this->_em->persist($b);
$this->_em->flush();

self::assertSame(1, $b->version);

$b->something = 'bar';
$this->_em->flush();

self::assertSame(2, $b->version);
}
}

/**
* @Entity
*/
class A
{
/**
* @Id
* @Column(type="integer")
* @var int
*/
public $id;

/**
* @Version
* @Column(type="integer")
* @var int
*/
public $version;

public function __construct(int $id)
{
$this->id = $id;
}
}

/**
* @Entity
*/
class B
{
/**
* @Id
* @ManyToOne(targetEntity="A")
* @JoinColumn(name="aid", referencedColumnName="id")
* @var A
*/
public $a;

/**
* @Column(type="string")
* @var string
*/
public $something;

/**
* @Version
* @Column(type="integer")
* @var int
*/
public $version;

public function __construct(A $a, string $something)
{
$this->a = $a;
$this->something = $something;
}
}

0 comments on commit 657a30f

Please sign in to comment.