diff --git a/lib/Doctrine/ORM/PersistentCollection.php b/lib/Doctrine/ORM/PersistentCollection.php index c79130c65..22404bbc7 100644 --- a/lib/Doctrine/ORM/PersistentCollection.php +++ b/lib/Doctrine/ORM/PersistentCollection.php @@ -878,6 +878,7 @@ final class PersistentCollection implements Collection, Selectable $expression = $criteria->getWhereExpression(); $expression = $expression ? $builder->andX($expression, $ownerExpression) : $ownerExpression; + $criteria = clone $criteria; $criteria->where($expression); $persister = $this->em->getUnitOfWork()->getEntityPersister($this->association['targetEntity']); diff --git a/tests/Doctrine/Tests/ORM/Functional/PersistentCollectionTest.php b/tests/Doctrine/Tests/ORM/Functional/PersistentCollectionTest.php index 375f7d3f9..c2181b8b1 100644 --- a/tests/Doctrine/Tests/ORM/Functional/PersistentCollectionTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/PersistentCollectionTest.php @@ -2,6 +2,7 @@ namespace Doctrine\Tests\ORM\Functional; +use Doctrine\Common\Collections\Criteria; use Doctrine\Common\Persistence\PersistentObject; /** @@ -69,6 +70,29 @@ class PersistentCollectionTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->assertFalse($collection->isEmpty()); $this->assertFalse($collection->isInitialized()); } + + /** + * @group #1206 + * @group DDC-3430 + */ + public function testMatchingDoesNotModifyTheGivenCriteria() + { + $collectionHolder = new PersistentCollectionHolder(); + + $this->_em->persist($collectionHolder); + $this->_em->flush(); + $this->_em->clear(); + + $criteria = new Criteria(); + + $collectionHolder = $this->_em->find(__NAMESPACE__ . '\PersistentCollectionHolder', $collectionHolder->getId()); + $collectionHolder->getCollection()->matching($criteria); + + $this->assertEmpty($criteria->getWhereExpression()); + $this->assertEmpty($criteria->getFirstResult()); + $this->assertEmpty($criteria->getMaxResults()); + $this->assertEmpty($criteria->getOrderings()); + } } /**