zfdatagrid / grid

A DataGrid library for Zend Framework
BSD 3-Clause "New" or "Revised" License
10 stars 16 forks source link

Bvb_Grid_Source_Doctrine2->getTotalRecords() =>NonUniqueResultException with groupBy #183

Closed imonteiro closed 11 years ago

imonteiro commented 11 years ago

Original author: david.qu...@gmail.com (August 18, 2011 12:54:01)

What steps will reproduce the problem? [code] $qb = $this->_em->createQueryBuilder() ->select('log.id') ->from('Entity\TErrorLog','log') ->groupBy('log.id');

$grid = $this->_helper->grid(); $source = new Bvb_Grid_Source_Doctrine2($qb); $grid->setSource($source); $this->view->grid = $grid->deploy(); => crash [/code] What is the expected output? What do you see instead? [code] Exception de type Doctrine\ORM\NonUniqueResultException

0 F:\ZEND\APPLICATIONS\exotica\zf1d2\library\Doctrine\ORM\Internal\Hydration\AbstractHydrator.php(99): Doctrine\ORM\Internal\Hydration\SingleScalarHydrator->_hydrateAll()

1 F:\ZEND\APPLICATIONS\exotica\zf1d2\library\Doctrine\ORM\AbstractQuery.php(594): Doctrine\ORM\Internal\Hydration\AbstractHydrator->hydrateAll(Object(Doctrine\DBAL\Driver\PDOStatement), Object(Doctrine\ORM\Query\ResultSetMapping), Array)

2 F:\ZEND\APPLICATIONS\exotica\zf1d2\library\Doctrine\ORM\AbstractQuery.php(459): Doctrine\ORM\AbstractQuery->execute(Array, 4)

3 F:\ZEND\APPLICATIONS\exotica\zf1d2\library\Doctrine\ORM\AbstractQuery.php(485): Doctrine\ORM\AbstractQuery->getSingleResult(4)

4 F:\ZEND\APPLICATIONS\exotica\zf1d2\library\Bvb\Grid\Source\Doctrine2.php(1146): Doctrine\ORM\AbstractQuery->getSingleScalarResult()

5 F:\ZEND\APPLICATIONS\exotica\zf1d2\library\Bvb\Grid.php(2779): Bvb_Grid_Source_Doctrine2->getTotalRecords()

6 F:\ZEND\APPLICATIONS\exotica\zf1d2\library\Bvb\Grid\Deploy\Table.php(1592): Bvb_Grid->deploy()

7 F:\ZEND\APPLICATIONS\exotica\zf1d2\application\modules\secret\controllers\MailingController.php(72): Bvb_Grid_Deploy_Table->deploy()

8 F:\ZEND\APPLICATIONS\exotica\zf1d2\library\Zend\Controller\Action.php(513): Secret_MailingController->listeAction()

9 F:\ZEND\APPLICATIONS\exotica\zf1d2\library\Zend\Controller\Dispatcher\Standard.php(295): Zend_Controller_Action->dispatch('listeAction')

10 F:\ZEND\APPLICATIONS\exotica\zf1d2\library\Zend\Controller\Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))

11 F:\ZEND\APPLICATIONS\exotica\zf1d2\library\Zend\Application\Bootstrap\Bootstrap.php(97): Zend_Controller_Front->dispatch()

12 F:\ZEND\APPLICATIONS\exotica\zf1d2\library\Zend\Application.php(366): Zend_Application_Bootstrap_Bootstrap->run()

13 F:\ZEND\APPLICATIONS\exotica\zf1d2\application\public\index.php(27): Zend_Application->run()

14 {main}

[/code]

Please insert the appropriate values; Zend Framework version: 1.11 ZFDatgrid Version (Bvb_Grid::getVersion()): latest Operating system: WinXP PHP Version: 5.3 Database Server and version: MySql 5 Source Adatapter: Bvb_Grid_Source_Doctrine2

Please provide any additional information below.

Original issue: http://code.google.com/p/zfdatagrid/issues/detail?id=745

imonteiro commented 11 years ago

From None on September 06, 2011 13:28:05 This issue was closed by revision r1863.

imonteiro commented 11 years ago

From nach...@gmail.com on February 02, 2012 23:40:43 Hi Bento. I'm having another exception not being catch by this TRY/CATCH block. Doctrine\ORM\NoResultException

Here's my solution:

try { $count = $qb->getQuery()->getSingleScalarResult(); } catch (NonUniqueResultException $e) { //when the result is non unique its most likely that a group by was used //if so, we just get the complete result and count the number of results //fixes issue #745 $result = $qb->getQuery()->getResult(); $count = count($result);

    } catch (Doctrine\ORM\NoResultException $e) {
        $count = 0;
    }