Doctrine/Symfony2 - DELETE FROM table WHERE field = "test"
doctrine, doctrine-orm, symfony
Solution
Search for the entity and remove it.
$em = $this->getDoctrine()->getEntityManager();
$repository = $em->getRepository('MyBundle:Product');
/** @var $product Product */
$product = $repository->findOneBy(array('field' => 'test'));
$em->remove($product);
$em->flush();
Problem
I can't believe I can't seem to find this anywhere (without just forcing the entire SQL in). Docs talk about adding, searching, updating and removing an entity, but I just can't see how to do what this would be in pure SQL: ``` DELETE FROM table WHERE field = "test" ``` I'm guessing this just adds and updates, so I can't use this: ``` $product = new Product(); // etc. $em = $this->getDoctrine()->getEntityManager(); $em->persist($product); $em->flush(); ``` and I don't think the 'remove' option would do it either: ``` $em->remove($product); $em->flush(); ``` So, can anyone point me in the right direction?