This is an old question and there seems to be no answer yet. For reference, I leave this here for more details. You can also check the doctrine documentation.
To delete an entry, you need (if you are in your controller):
// get EntityManager $em = $this->getDoctrine()->getManager(); // Get a reference to the entity ( will not generate a query ) $user = $em->getReference('ProjectBundle:User', $id); // OR you can get the entity itself ( will generate a query ) // $user = $em->getRepository('ProjectBundle:User')->find($id); // Remove it and flush $em->remove($user); $em->flush();
Using the first method to get the reference is usually better if you just want to delete the object without first checking whether it exists or not, because it will not query the database and will only create a proxy object that you can use to delete your entity.
If you want to make sure that this identifier matches the actual entity first, then the second method is better because it will query the database for your entity before trying to delete it.
source share