Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[DDC-2340] Fix bug with dirty collection matching + ordering.

  • Loading branch information...
commit eca468b9d1a31e621fd32d1c4082dcb5db74701a 1 parent dba63c5
@beberlei beberlei authored
View
13 lib/Doctrine/ORM/PersistentCollection.php
@@ -838,6 +838,10 @@ public function __clone()
*/
public function matching(Criteria $criteria)
{
+ if ($this->isDirty) {
+ $this->initialize();
+ }
+
if ($this->initialized) {
return $this->coll->matching($criteria);
}
@@ -846,13 +850,6 @@ public function matching(Criteria $criteria)
throw new \RuntimeException("Matching Criteria on PersistentCollection only works on OneToMany associations at the moment.");
}
- // If there are NEW objects we have to check if any of them matches the criteria
- $newObjects = array();
-
- if ($this->isDirty) {
- $newObjects = $this->coll->matching($criteria)->toArray();
- }
-
$id = $this->em
->getClassMetadata(get_class($this->owner))
->getSingleIdReflectionProperty()
@@ -866,6 +863,6 @@ public function matching(Criteria $criteria)
$persister = $this->em->getUnitOfWork()->getEntityPersister($this->association['targetEntity']);
- return new ArrayCollection(array_merge($persister->loadCriteria($criteria), $newObjects));
+ return new ArrayCollection($persister->loadCriteria($criteria));
}
}
View
26 tests/Doctrine/Tests/ORM/Functional/OneToManyBidirectionalAssociationTest.php
@@ -173,14 +173,36 @@ public function testMatching()
$this->assertInstanceOf('Doctrine\Common\Collections\Collection', $results);
$this->assertEquals(2, count($results));
}
-
+
+ /**
+ * @group DDC-2340
+ */
+ public function testMatchingOnDirtyCollection()
+ {
+ $this->_createFixture();
+
+ $product = $this->_em->find('Doctrine\Tests\Models\ECommerce\ECommerceProduct', $this->product->getId());
+
+ $thirdFeature = new ECommerceFeature();
+ $thirdFeature->setDescription('Model writing tutorial');
+
+ $features = $product->getFeatures();
+ $features->add($thirdFeature);
+
+ $results = $features->matching(new Criteria(
+ Criteria::expr()->eq('description', 'Model writing tutorial')
+ ));
+
+ $this->assertEquals(2, count($results));
+ }
+
public function testMatchingBis()
{
$this->_createFixture();
$product = $this->_em->find('Doctrine\Tests\Models\ECommerce\ECommerceProduct', $this->product->getId());
$features = $product->getFeatures();
-
+
$thirdFeature = new ECommerceFeature();
$thirdFeature->setDescription('Third feature');
$product->addFeature($thirdFeature);
View
2  tests/Doctrine/Tests/ORM/Mapping/BasicInheritanceMappingTest.php
@@ -115,7 +115,7 @@ public function testUnmappedSuperclassInHierarchy()
*/
public function testUnmappedEntityInHierarchy()
{
- $this->setExpectedException('Doctrine\ORM\Mapping\MappingException', "Entity 'Doctrine\Tests\ORM\Mapping\HierarchyBEntity' has to be part of the discriminator map of 'Doctrine\Tests\ORM\Mapping\HierarchyBase' to be properly mapped in the inheritance hierarchy. Alternatively you can make 'Doctrine\Tests\ORM\Mapping\HierarchyBEntity' an abstract class to avoid this exception from occuring.");
+ $this->setExpectedException('Doctrine\ORM\Mapping\MappingException', "Entity 'Doctrine\Tests\ORM\Mapping\HierarchyBEntity' has to be part of the discriminator map of 'Doctrine\Tests\ORM\Mapping\HierarchyBase' to be properly mapped in the inheritance hierarchy. Alternatively you can make 'Doctrine\Tests\ORM\Mapping\HierarchyBEntity' an abstract class to avoid this exception from occurring.");
$class = $this->_factory->getMetadataFor(__NAMESPACE__ . '\\HierarchyE');
}
Please sign in to comment.
Something went wrong with that request. Please try again.