I'm using this function to copy content of a manyToMany relationship table
private function cloneProductDistributor($origin_distributor, $destiny_distributor){
$products = $origin_distributor->getProducts();
foreach ($products as $product){
$destiny_distributor->addProduct($product);
}
$this->em->persist($destiny_distributor);
$this->em->flush();
}
in the entity we had
/**
*
* @ORM\ManyToMany(targetEntity="AppBundle\Entity\Product", mappedBy="distributors")
*/
private $products;
/**
* @return mixed
*/
public function getProducts()
{
return $this->products;
}
/**
* Add product
*
* @param Product $product
*
* @return Distributor
*/
public function addProduct(Product $product)
{
$this->products[] = $product;
return $this;
}
Debugging I have checked that the content of $destiny_distributor
is correct but when I check the database is not stored,do I missed something?