Doctrine2 update both sides of association

Posted by orourkedd on Stack Overflow See other posts from Stack Overflow or by orourkedd
Published on 2012-09-07T21:35:31Z Indexed on 2012/09/07 21:38 UTC
Read the original article Hit count: 394

Filed under:
|

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

© Stack Overflow or respective owner

Related posts about doctrine2

Related posts about associations