Skip to content

Commit

Permalink
Added fix for collection->contains when many-to-many extra lazy fetch…
Browse files Browse the repository at this point in the history
…Mode
  • Loading branch information
danielholmes authored and beberlei committed Jan 18, 2012
1 parent 286eef1 commit be6890e
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/Doctrine/ORM/Persisters/ManyToManyPersister.php
Expand Up @@ -254,7 +254,9 @@ public function contains(PersistentCollection $coll, $element)
$uow = $this->_em->getUnitOfWork();

// shortcut for new entities
if ($uow->getEntityState($element, UnitOfWork::STATE_NEW) == UnitOfWork::STATE_NEW) {
$entityState = $uow->getEntityState($element, UnitOfWork::STATE_NEW);
if ($entityState == UnitOfWork::STATE_NEW ||
($entityState == UnitOfWork::STATE_MANAGED && $uow->isScheduledForInsert($element))) {
return false;
}

Expand Down
@@ -0,0 +1,55 @@
<?php

namespace Doctrine\Tests\ORM\Functional;

use Doctrine\Common\Collections\ArrayCollection;
require_once __DIR__ . '/../../TestInit.php';

/**
*
*/
class ManyToManyExtraLazyContainsTest extends \Doctrine\Tests\OrmFunctionalTestCase
{
public function setUp()
{
$this->useModelSet('company');
parent::setUp();
}

public function testManyToManyExtraLazyContainsAddedPendingInsertEntityIsTrue()
{
$contract = new \Doctrine\Tests\Models\Company\CompanyFlexContract();

$this->_em->persist($contract);
$this->_em->flush();

$this->_em->clear();
$contract = $this->_em->find('Doctrine\Tests\Models\Company\CompanyFlexContract', $contract->getId());

$pendingInsertManager = new \Doctrine\Tests\Models\Company\CompanyManager();
$this->_em->persist($pendingInsertManager);
$contract->getManagers()->add($pendingInsertManager);

$result = $contract->getManagers()->contains($pendingInsertManager);

$this->assertTrue($result);
}

public function testManyToManyExtraLazyContainsNonAddedPendingInsertEntityIsFalse()
{
$contract = new \Doctrine\Tests\Models\Company\CompanyFlexContract();

$this->_em->persist($contract);
$this->_em->flush();

$this->_em->clear();
$contract = $this->_em->find('Doctrine\Tests\Models\Company\CompanyFlexContract', $contract->getId());

$pendingInsertManager = new \Doctrine\Tests\Models\Company\CompanyManager();
$this->_em->persist($pendingInsertManager);

$result = $contract->getManagers()->contains($pendingInsertManager);

$this->assertFalse($result);
}
}

0 comments on commit be6890e

Please sign in to comment.