5

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.

Codium
  • 3,200
  • 6
  • 34
  • 60
  • How to build subquery in Doctrine2 you can [found here](http://stackoverflow.com/questions/6637506/doing-a-where-in-subquery-in-doctrine-2#6638146). – jkucharovic Feb 01 '12 at 06:33
  • Thanks but probably I can't pass sub select to join in QueryBuilder, I need to use native SQL. – Codium Feb 01 '12 at 11:37

1 Answers1

1

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

Community
  • 1
  • 1
Steve Tauber
  • 9,551
  • 5
  • 42
  • 46