Doctrine Relations, Breaking ManyToMany when I clone an entity

210 Views Asked by At

So I'm creating a doctrine entity, called exhibitors. This entity has relationships to 2 other entities, both are ManyToMany relationships. They are Quotes and Services.

When I clone the exhibitor, it also clones all existing quotes and services with new ids.

Is there a way I can prevent the relations cloning as well, I just want to clone the Exhibitor?

Does anyone know?

At present I'm just doing

*   $newExhibitor = clone $exhibitor;
    $this->entityManager->getEntityManager()->persist($newExhibitor);
    $this->entityManager->getEntityManager()->flush();*
1

There are 1 best solutions below

1
On BEST ANSWER

Why do you clone an exhibitor ? Do you need 2 identical Exhibitor in your database ? Did you try setting to null before persist ?:

$newExhibitor = clone $exhibitor;
$newExhibitor->setQuotes(null);
$newExhibitor->setServices(null);
$this->entityManager->getEntityManager()->persist($newExhibitor);
$this->entityManager->getEntityManager()->flush();