[2.0] resolved hydrateAdd() recursivity
This commit is contained in:
parent
c073f1d113
commit
82c416686e
2 changed files with 5 additions and 7 deletions
|
@ -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));
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue