You can not access e.subject.id
without a join in your query. But a join is not possible in a Doctrine update statement, since its MySQL specific.
What should work is to compare the whole entity:
$subject = $this->getEntityManager()->getRepository('namespace\subject')
->find(xxx);
$query = $this->getEntityManager()->createQueryBuilder()
->update('namespace\Exam', 'e')
->set('e.marks', '4')
->where('e.subject = :subject')
->setParameter('subject', $subject);
Or, if you don't want to have another database query and the primary key of your subject entity consists only of one column (e.g. id
), you could also compare with this primary key:
$query = $this->getEntityManager()->createQueryBuilder()
->update('namespace\Exam', 'e')
->set('e.marks', '4')
->where('e.subject = :id')
->setParameter('id', xxx);
Also have a look at this question, the user wasn't able to join in his update statement too.
Edit: added more general approach