agrupar por mas de un campo en dql

41 views
Skip to first unread message

Nicolas Esteban

unread,
Aug 10, 2016, 4:28:45 AM8/10/16
to symfony-es
Hola, alguien saber como agrupar por mas de un campo en DQL, la consulta en sql me funciona pero cuando la replico
en dql no. (SELECT * FROM tabla GROUP BY campo_1, campo_2)
Gracias, Saludos.

Vladimir Moran

unread,
Aug 11, 2016, 5:21:09 PM8/11/16
to symfony-es
Paa el caso de realizar DQL debes agregar addGroupBy() 

$qb = $this->createQueryBuilder('m')
    ->where('m.from = ?1 or m.to = ?1')
    ->groupBy('m.to')
    ->addGroupBy('m.from')
    ->orderBy('m.date', 'DESC')
    ->setParameter(1, $user->getId())
    ->setMaxResults($pagination) // limit
    ->setFirstResult($pagination * $page) // offset
;

Nicolas Esteban

unread,
Aug 18, 2016, 4:17:52 PM8/18/16
to symfony-es
Perfecto, lo probe y funciona, muchismas gracias!
Reply all
Reply to author
Forward
0 new messages