diff --git a/src/Controller/AdminController.php b/src/Controller/AdminController.php index 4b9691b..1b519a9 100644 --- a/src/Controller/AdminController.php +++ b/src/Controller/AdminController.php @@ -205,6 +205,7 @@ class AdminController extends AbstractController /** @var User $user */ $user = $userRepo->find($id); + $prevSup = $this->entityManager->getRepository(Supervision::class)->findBy(['user' => $user]); $form = $this->createForm(SupervisorFormType::class); $form->handleRequest($request); @@ -212,6 +213,11 @@ class AdminController extends AbstractController if ($form->isSubmitted() && $form->isValid()) { $supervisor = $form->get('supervisor')->getData(); + if (count($prevSup) > 0) { + $this->entityManager->remove($prevSup[0]); + $this->entityManager->flush(); + } + $sup = new Supervision(); $sup->setSupervisor($supervisor); $sup->setWorker($user);