Skip to content

Commit

Permalink
Merge branch 'backport/fix/l2c-version' into 2.6
Browse files Browse the repository at this point in the history
Backporting #7069
  • Loading branch information
lcobucci committed Feb 17, 2018
2 parents 496c6a9 + 8e73926 commit 794c770
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/Doctrine/ORM/Cache/DefaultEntityHydrator.php
Expand Up @@ -75,6 +75,10 @@ public function buildCacheEntry(ClassMetadata $metadata, EntityCacheKey $key, $e
$data = $this->uow->getOriginalEntityData($entity);
$data = array_merge($data, $metadata->getIdentifierValues($entity)); // why update has no identifier values ?
if ($metadata->isVersioned) {
$data[$metadata->versionField] = $metadata->getFieldValue($entity, $metadata->versionField);
}

foreach ($metadata->associationMappings as $name => $assoc) {
if ( ! isset($data[$name])) {
continue;
Expand Down
69 changes: 69 additions & 0 deletions tests/Doctrine/Tests/ORM/Functional/Ticket/GH7067Test.php
@@ -0,0 +1,69 @@
<?php
declare(strict_types=1);

namespace Doctrine\Tests\ORM\Functional\Ticket;

final class GH7067Test extends \Doctrine\Tests\OrmFunctionalTestCase
{
public function setUp() : void
{
$this->enableSecondLevelCache();
parent::setUp();

$this->setUpEntitySchema([GH7067Entity::class]);
}

/**
* @group 7067
*/
public function testSLCWithVersion() : void
{
$entity = new GH7067Entity();
$entity->lastUpdate = new \DateTime();

$this->_em->persist($entity);
$this->_em->flush();
$this->_em->clear();

/** @var GH7067Entity $notCached */
$notCached = $this->_em->find(GH7067Entity::class, $entity->id);

self::assertNotNull($notCached->version, 'Version already cached by persister above, it must be not null');

$notCached->lastUpdate = new \DateTime();

$this->_em->flush();
$this->_em->clear();
}
}

/**
* @Entity()
* @Cache(usage="NONSTRICT_READ_WRITE")
*/
class GH7067Entity
{
/**
* @Id
* @GeneratedValue
* @Column(type="integer")
*
* @var int
*/
public $id;

/**
* @Column(type="datetime")
*
* @var \DateTime
*/
public $lastUpdate;

/**
* @Column(type="datetime")
* @Version
*
* @var \DateTime
*/
public $version;
}

0 comments on commit 794c770

Please sign in to comment.