1
0
Fork 0
mirror of synced 2025-04-01 12:26:11 +03:00

[2.0] resolved hydrateAdd() recursivity

This commit is contained in:
piccoloprincipe 2009-07-28 12:30:35 +00:00
parent c073f1d113
commit 82c416686e
2 changed files with 5 additions and 7 deletions

View file

@ -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;
}

View file

@ -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));