Ver Mensaje Individual
  #1 (permalink)  
Antiguo 15/10/2011, 16:37
Avatar de punk567
punk567
 
Fecha de Ingreso: septiembre-2006
Ubicación: Montevideo
Mensajes: 265
Antigüedad: 17 años, 7 meses
Puntos: 5
LeftJoin + setMaxResults

Hola,

Estoy intentando limitar los resultados de una consulta con setMaxResults. La consulta tiene un LeftJoin de dos tablas

Código:
$qb = $this->createQueryBuilder('b')
           ->select('b, c')
           ->leftJoin('b.comments', 'c')
           ->groupBy('b')
           ->addOrderBy('b.created', 'DESC');

        if (false === is_null($limit))
            $qb->setMaxResults($limit);

        return $qb->getQuery()
                  ->getResult();

El problema es que el límite funciona bien, pero los comentarios asociados siempre devuelven 1, en el template: {{ blog.comments|length }}

He leído en la documentación de Doctrine que setMaxResults() no funciona correctamente en consultas con "fetch-join"

Cita:
If your query contains a fetch-joined collection specifying the result limit methods are not working as you would expect. Set Max Results restricts the number of database result rows, however in the case of fetch-joined collections one root entity might appear in many rows, effectively hydrating less than the specified number of results.
Alguna idea de como establecer el máximo de resultados?