0

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();*
Hasitha Jayawardana
  • 2,326
  • 4
  • 18
  • 36

1 Answers1

0

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();
Nsy
  • 71
  • 4
  • Ah yes so simple, I didnt do this but instead did a __clone() {} method that sets the property to null .. pretty much what you suggested. – James Prince Mar 27 '19 at 15:19