/** * Deletes a Team entity. * */ public function deleteAction(Request $request, Team $team) { $em = $this->getDoctrine()->getManager(); $gameId = $team->getGame()->getId(); $query = $em->createQuery('SELECT u FROM AppBundle:Application u where u.team=' . $team->getId()); $applications = $query->getResult(); foreach ($applications as $application) { $em->remove($application); } $query = $em->createQuery('SELECT u FROM AppBundle:Player u where u.team=' . $team->getId()); $players = $query->getResult(); foreach ($players as $player) { $player->setTeam(null); if ($player->getCapitain()) { $player->setCapitain(null); } $em->persist($player); } $em->remove($team); $em->flush(); return $this->forward('AppBundle:Game:show', array('id' => $gameId)); }