How I can to do setter for children that doctrine save relation for this:
/**
* @ORM\ManyToMany(targetEntity="User", mappedBy="parents", cascade={"persist"})
*/
private $children;
/**
* @ORM\ManyToMany(targetEntity="User", inversedBy="children")
* @ORM\JoinTable(
* name="family",
* joinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="family_user_id", referencedColumnName="id")}
* )
*/
private $parents;
/**
* User constructor.
*/
public function __construct()
{
$this->children = new \Doctrine\Common\Collections\ArrayCollection();
$this->parents = new \Doctrine\Common\Collections\ArrayCollection();
}
My setter, it dont' throw error and don't save relation:
/**
* @param mixed $children
*/
public function setChildren($children)
{
$this->children[] = $children;
$children->setParents($this);
}
Users doctrine save, relation not.