Skip to content

Commit

Permalink
Fixes GH-44 - Out of bounds query returns all results.
Browse files Browse the repository at this point in the history
  • Loading branch information
beberlei committed Feb 19, 2012
1 parent d726b29 commit 4ea498a
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions lib/DoctrineExtensions/Paginate/Paginate.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,22 +94,22 @@ static public function createLimitSubQuery(Query $query, $offset, $itemCountPerP
static public function createWhereInQuery(Query $query, array $ids, $namespace = 'pgid')
{
// don't do this for an empty id array
if (count($ids) > 0) {
$whereInQuery = clone $query;

$whereInQuery->setParameters($query->getParameters());

$whereInQuery->setHint(Query::HINT_CUSTOM_TREE_WALKERS, array('DoctrineExtensions\Paginate\WhereInWalker'));
$whereInQuery->setHint('id.count', count($ids));
$whereInQuery->setHint('pg.ns', $namespace);
$whereInQuery->setFirstResult(null)->setMaxResults(null);
foreach ($ids as $i => $id) {
$i = $i+1;
$whereInQuery->setParameter("{$namespace}_{$i}", $id);
}
return $whereInQuery;
} else {
return $query;
if (count($ids) == 0) {
throw new \RuntimeException("No ids given, cannot create where in query in this case.");
}

$whereInQuery = clone $query;

$whereInQuery->setParameters($query->getParameters());

$whereInQuery->setHint(Query::HINT_CUSTOM_TREE_WALKERS, array('DoctrineExtensions\Paginate\WhereInWalker'));
$whereInQuery->setHint('id.count', count($ids));
$whereInQuery->setHint('pg.ns', $namespace);
$whereInQuery->setFirstResult(null)->setMaxResults(null);
foreach ($ids as $i => $id) {
$i = $i+1;
$whereInQuery->setParameter("{$namespace}_{$i}", $id);
}
return $whereInQuery;
}
}

0 comments on commit 4ea498a

Please sign in to comment.