Commit 82c41668 authored by piccoloprincipe's avatar piccoloprincipe

[2.0] resolved hydrateAdd() recursivity

parent c073f1d1
......@@ -203,13 +203,10 @@ final class PersistentCollection extends \Doctrine\Common\Collections\Collection
*
* @param mixed $element The element to add.
*/
public function hydrateAdd($element)
public function hydrateAdd($element, $setBackRef = true)
{
if (parent::contains($element)) {
return;
}
parent::add($element);
if ($this->_backRefFieldName) {
if ($this->_backRefFieldName and $setBackRef) {
// Set back reference to owner
if ($this->_association->isOneToMany()) {
// OneToMany
......@@ -219,7 +216,7 @@ final class PersistentCollection extends \Doctrine\Common\Collections\Collection
// ManyToMany
$otherCollection = $this->_typeClass->reflFields[$this->_backRefFieldName]
->getValue($element);
$otherCollection->hydrateAdd($this->_owner);
$otherCollection->hydrateAdd($this->_owner, false);
}
}
}
......@@ -242,6 +239,7 @@ final class PersistentCollection extends \Doctrine\Common\Collections\Collection
private function _initialize()
{
if (!$this->_initialized) {
parent::clear();
$this->_association->load($this->_owner, $this, $this->_em);
$this->_initialized = true;
}
......
......@@ -134,7 +134,7 @@ class ManyToManyBidirectionalAssociationTest extends AbstractManyToManyAssociati
$categories = $firstProduct->getCategories();
$firstCategoryProducts = $categories[0]->getProducts();
$secondCategoryProducts = $categories[1]->getProducts();
$this->assertEquals(2, count($firstCategoryProducts));
$this->assertEquals(2, count($secondCategoryProducts));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment