drupality drupality - 1 year ago 200
MySQL Question

How to create LEFT JOIN with SELECT subquery using QueryBuilder in Doctrine 2?

I need to limit LEFT JOIN results, so I must use subquery.
Could somebody give me advice how can I do it with Doctrine 2?

What I have now is:

$qb = $this->_em->createQueryBuilder();
return $qb->add('select', 'c,j')
->add('from', 'JobeetBundle:Category c')
->leftJoin('c.jobs', 'j', 'WITH', 'j.category = c')
->add('where', 'j.expiresAt > ?1')
->add('orderBy','j.expiresAt DESC')
->setParameter(1, new \DateTime())

but I must change it to limit jobs results to 10 by every category.

Answer Source

Unfortunately, This is not possible. Per here:


You can do it using IN here:

Doing a WHERE .. IN subquery in Doctrine 2

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download