How to create LEFT JOIN with SELECT subquery using

2020-03-04 02:37发布

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())
             ->getQuery()
             ->getResult();

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

1条回答
Luminary・发光体
2楼-- · 2020-03-04 02:53

Unfortunately, This is not possible. Per here:

https://groups.google.com/forum/#!topic/doctrine-user/0rNbXlD0E_8

You can do it using IN here:

Doing a WHERE .. IN subquery in Doctrine 2

查看更多
登录 后发表回答