Added fix for collection->contains with many-to-many extra lazy fetchMode #259

Merged
merged 2 commits into from Jan 17, 2012

Projects

None yet

3 participants

@danielholmes

That case previously triggered a PHP error along the lines of:

Notice: Undefined index: 0000000062a3a7690000000033c91b26 in doctrine/lib/Doctrine/ORM/UnitOfWork.php line 2202
#0 doctrine/lib/Doctrine/ORM/Persisters/ManyToManyPersister.php(267): Doctrine\ORM\UnitOfWork->getEntityIdentifier(Object(Item))
#1 doctrine/lib/Doctrine/ORM/PersistentCollection.php(411): Doctrine\ORM\Persisters\ManyToManyPersister->contains(Object(Doctrine\ORM\PersistentCollection), Object(Item))
#2 Test.php(71): Doctrine\ORM\PersistentCollection->contains(Object(Item))

@stof stof and 1 other commented on an outdated diff Jan 15, 2012
lib/Doctrine/ORM/Persisters/ManyToManyPersister.php
@@ -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 ||
@stof
stof Jan 15, 2012

couldn't it be a strict comparison here ?

@danielholmes
danielholmes Jan 15, 2012

Yea I feel like it could, but the comparison already there was "==". There are other places all over the code base using that comparison when it could be strict so i figured it was probably for a reason, whether that be coding style or a micro optimisation or something else. I've changed it and commited

@guilhermeblanco guilhermeblanco merged commit c1012f7 into doctrine:master Jan 17, 2012
@guilhermeblanco
Doctrine member

@beberlei please merge into 2.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment