Question

assume I have two objects article and comment. What I would like to do is to fetch all comments, which article.id is IN (1,2,3,4). What is the best way to achieve it ? Am I forced to use JOIN? Right now I have something like this;

dql = "SELECT c FROM Comment c LEFT OUTER JOIN c.article a WHERE a.id IN :articles ORDER BY a.id ASC";
$query = $this->entityManager->createQuery($dql);
$query->setParameter("articles", array(1,2,3,4));

I haven't tested this query but I believe something like this should work, but it would be lovely to write something like c.article IN articles (without JOIN)

Was it helpful?

Solution

This does work, AFAIK:

SELECT c FROM Comment c WHERE c.article IN(:articles)
$query->setParameter('articles', array(1,2,3,4));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top