Doctrine2 update both sides of association
- by orourkedd
I'm using this to update both sides of an association but want to know if there is a more efficient way to do this. In this case, it is a self-referencing OneToMany parent/child association:
public function setParent(Node $parent, $inverse = true)
{
$this->parent = $parent;
if($inverse)
$parent->addChild($this, false);
}
public function addChild(Node $child, $inverse = true)
{
if(!$this->children->contains($child))
{
$this->children[] = $child;
if($inverse)
$child->setParent($this, false);
}
}