2

In my application there is a Case entity that has a collection of Operator entities.

When I execute this request :

$this->createQueryBuilder('c')
    ->leftJoin('c.operators', 'od') // d -> one-to-many -> operator
    ->setMaxResults(100)
    ->getQuery()
    ->getResult()
;

I get only 71 result (suppose that are Cases without any Operator).

Hydrating to array works well when there is no selection:

$this->createQueryBuilder('c')
    ->select('c, od') // notice select here which yields to 71 results (without it I get 100 results)
    ->leftJoin('c.operators', 'od')
    ->setMaxResults(100)
    ->getQuery()
    ->getArrayResult()
;

The things get really confusing as the real SQL obtained with ->getSQL() returns 100 results in both cases.

Anyone can help ?


UPDATE

Actually I have precicely 100 results in the result set. These results are Cases combined with Operators. When Dossier in the result set has multiple Operators when this Dossier enters multiple times to the result set. Doctrine automatically shrinks this result set of 100 lines to the array of 71 unique Cases.

VladRia
  • 1,475
  • 3
  • 20
  • 32
  • I think you should select from operators and then join (or "left join") the case (not the other way around). Did you try that? – Tobias Xy Oct 24 '17 at 10:17
  • What does your database query log have in both cases? – svgrafov Oct 24 '17 at 10:20
  • There is an important update in the question. – VladRia Oct 24 '17 at 10:28
  • Possible duplicate of [Limiting a doctrine query with a fetch-joined collection?](https://stackoverflow.com/questions/5620771/limiting-a-doctrine-query-with-a-fetch-joined-collection) – simon.ro Oct 24 '17 at 10:31
  • There is nothing to do with Doctrine. Take a look on https://github.com/KnpLabs/KnpPaginatorBundle, it will do this job for you (using additional query). – Ivan Kalita Oct 25 '17 at 18:17

0 Answers0