SELECT - all right, no errors
$em = $this->get('doctrine.orm.entity_manager');
$query = $em->createQuery("
SELECT c
FROM MyDemoBundle:Category c
LEFT JOIN c.projects p
WHERE c.isActive = true
AND p.id = 1
");
$result = $query->getResult();
UPDATE - exception [Semantical Error]
$query = $em->createQuery("
UPDATE MyDemoBundle:Category c
LEFT JOIN c.projects p
SET c.isActive = false
WHERE p.id = ?1
");
$query->setParameter(1, $id);
$query->execute();
LEFT JOIN, or JOINs in particular are only supported in UPDATE statements of MySQL. DQL abstracts a subset of common ansi sql, so this is not possible. Try with a subselect:
UPDATE MyDemoBundle:Category c SET c.isActive = false WHERE ?1 MEMBER OF c.projects;
(MEMBER OF is actually turning into a subselect here). I am not 100% sure if this works, but it is more likeli than the join.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With