/** * To delete keywords during the update of interactionHole * * @access private * * @param \UJM\ExoBundle\Entity\Hole $hole * @param Collection of \UJM\ExoBundle\Entity\Hole $originalHoles * */ private function delKeyWord($hole, $originalHoles) { $wordResponses = $hole->getWordResponses()->toArray(); foreach ($originalHoles as $holeOrig) { $originalWords = $holeOrig->getwordResponses()->getSnapshot(); if ($hole->getId() === $holeOrig->getId()) { foreach ($wordResponses as $word) { foreach ($originalWords as $key => $toDel) { if ($toDel->getId() === $word->getId()) { unset($originalWords[$key]); } } } // remove the relationship between the hole and the interactionhole foreach ($originalWords as $word) { // remove the wr from the wordResponse $hole->getWordResponses()->removeElement($word); // if you wanted to delete the Hole entirely, you can also do that $this->em->remove($word); } } } }