1
0
mirror of synced 2025-01-22 00:01:40 +03:00

[DDC-1129] Fix bug in version changeset computation aswell as inline ClassMetadata::isCollectionValuedAssociation to increase performance by 2-5%

This commit is contained in:
Benjamin Eberlei 2011-05-01 11:44:31 +02:00
parent b5520aa304
commit d4569baa11
2 changed files with 51 additions and 2 deletions

View File

@ -406,8 +406,11 @@ class UnitOfWork implements PropertyChangedListener
$actualData = array();
foreach ($class->reflFields as $name => $refProp) {
$value = $refProp->getValue($entity);
if ($class->isCollectionValuedAssociation($name) && $value !== null
if (isset($class->associationMappings[$name])
&& ($class->associationMappings[$name]['type'] & ClassMetadata::TO_MANY)
&& $value !== null
&& ! ($value instanceof PersistentCollection)) {
// If $value is not a Collection then use an ArrayCollection.
if ( ! $value instanceof Collection) {
$value = new ArrayCollection($value);
@ -426,7 +429,7 @@ class UnitOfWork implements PropertyChangedListener
$coll->setDirty( ! $coll->isEmpty());
$class->reflFields[$name]->setValue($entity, $coll);
$actualData[$name] = $coll;
} else if ( ! $class->isIdentifier($name) || ! $class->isIdGeneratorIdentity()) {
} else if ( (! $class->isIdentifier($name) || ! $class->isIdGeneratorIdentity()) && ($name !== $class->versionField) ) {
$actualData[$name] = $value;
}
}

View File

@ -0,0 +1,46 @@
<?php
namespace Doctrine\Tests\ORM\Functional\Ticket;
use Doctrine\Common\Collections\ArrayCollection;
require_once __DIR__ . '/../../../TestInit.php';
/**
* @group DDC-1129
*/
class DDC1129Test extends \Doctrine\Tests\OrmFunctionalTestCase
{
public function setUp()
{
$this->useModelSet('cms');
parent::setUp();
}
public function testVersionFieldIgnoredInChangesetComputation()
{
$article = new \Doctrine\Tests\Models\CMS\CmsArticle();
$article->text = "I don't know.";
$article->topic = "Who is John Galt?";
$this->_em->persist($article);
$this->_em->flush();
$this->assertEquals(1, $article->version);
$class = $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsArticle');
$uow = $this->_em->getUnitOfWork();
$uow->computeChangeSet($class, $article);
$changeSet = $uow->getEntityChangeSet($article);
$this->assertEquals(0, count($changeSet), "No changesets should be computed.");
$article->text = "This is John Galt speaking.";
$this->_em->flush();
$this->assertEquals(2, $article->version);
$uow->computeChangeSet($class, $article);
$changeSet = $uow->getEntityChangeSet($article);
$this->assertEquals(0, count($changeSet), "No changesets should be computed.");
}
}