1
0
mirror of synced 2025-01-20 15:31:40 +03:00

[DDC-1918] Fix weird results at the end of paginator when using fetch joins

This commit is contained in:
Benjamin Eberlei 2012-08-29 15:14:14 +02:00
parent 9c682efb2f
commit bc2476f342
3 changed files with 74 additions and 12 deletions

View File

@ -174,7 +174,10 @@ class Paginator implements \Countable, \IteratorAggregate
$whereInQuery = $this->cloneQuery($this->query); $whereInQuery = $this->cloneQuery($this->query);
// don't do this for an empty id array // don't do this for an empty id array
if (count($ids) > 0) { if (count($ids) == 0) {
return new \ArrayIterator(array());
}
$namespace = WhereInWalker::PAGINATOR_ID_ALIAS; $namespace = WhereInWalker::PAGINATOR_ID_ALIAS;
$whereInQuery->setHint(Query::HINT_CUSTOM_TREE_WALKERS, array('Doctrine\ORM\Tools\Pagination\WhereInWalker')); $whereInQuery->setHint(Query::HINT_CUSTOM_TREE_WALKERS, array('Doctrine\ORM\Tools\Pagination\WhereInWalker'));
@ -184,7 +187,6 @@ class Paginator implements \Countable, \IteratorAggregate
$i++; $i++;
$whereInQuery->setParameter("{$namespace}_{$i}", $id); $whereInQuery->setParameter("{$namespace}_{$i}", $id);
} }
}
$result = $whereInQuery->getResult($this->query->getHydrationMode()); $result = $whereInQuery->getResult($this->query->getHydrationMode());
} else { } else {

View File

@ -5,8 +5,6 @@ namespace Doctrine\Tests\ORM\Functional\Ticket;
use Doctrine\Tests\Models\Quote\Group; use Doctrine\Tests\Models\Quote\Group;
use Doctrine\Tests\Models\Quote\User; use Doctrine\Tests\Models\Quote\User;
require_once __DIR__ . '/../../../TestInit.php';
/** /**
* @group DDC-1845 * @group DDC-1845
* @group DDC-1885 * @group DDC-1885

View File

@ -0,0 +1,62 @@
<?php
namespace Doctrine\Tests\ORM\Functional\Ticket;
use Doctrine\Tests\Models\CMS\CmsUser;
use Doctrine\Tests\Models\CMS\CmsGroup;
use Doctrine\ORM\Tools\Pagination\Paginator;
/**
* @group DDC-1918
*/
class DDC1918Test extends \Doctrine\Tests\OrmFunctionalTestCase
{
protected function setUp()
{
$this->useModelSet('cms');
parent::setUp();
}
public function testLastPageCorrect()
{
$groups = array();
for ($i = 0; $i < 3; $i++) {
$group = new CmsGroup();
$group->name = "test";
$this->_em->persist($group);
$groups[] = $group;
}
for ($i = 0; $i < 10; $i++) {
$user = new CmsUser();
$user->username = "user$i";
$user->name = "user$i";
$user->status = "active";
$user->groups = $groups;
$this->_em->persist($user);
}
$this->_em->flush();
$query = $this->_em->createQuery('SELECT u, g FROM Doctrine\Tests\Models\CMS\CmsUser u JOIN u.groups g');
$query->setFirstResult(6);
$query->setMaxResults(3);
$paginator = new Paginator($query, true);
$this->assertEquals(3, count(iterator_to_array($paginator)));
$query->setFirstResult(8);
$query->setMaxResults(3);
$paginator = new Paginator($query, true);
$this->assertEquals(2, count(iterator_to_array($paginator)));
$query->setFirstResult(10);
$query->setMaxResults(3);
$paginator = new Paginator($query, true);
$this->assertEquals(0, count(iterator_to_array($paginator)));
}
}