Skip to content

Commit

Permalink
Use Paginator for ProxyQuery
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentLanglet committed May 2, 2021
1 parent 7df241b commit ae31060
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
19 changes: 18 additions & 1 deletion src/Datagrid/ProxyQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Query;
use Doctrine\ORM\QueryBuilder;
use Doctrine\ORM\Tools\Pagination\Paginator;

/**
* This class try to unify the query usage with Doctrine.
Expand Down Expand Up @@ -205,7 +206,23 @@ public function execute(array $params = [], $hydrationMode = null)
$query->setHint($name, $value);
}

return $query->execute($params, $hydrationMode);
// NEXT_MAJOR: Remove this.
if (\func_num_args() > 0) {
return $query->execute($params, $hydrationMode);
}

$identifierFieldNames = $this
->getQueryBuilder()
->getEntityManager()
->getMetadataFactory()
->getMetadataFor(current($this->getQueryBuilder()->getRootEntities()))
->getIdentifierFieldNames();

// Paginator with fetchJoinCollection doesn't work with composite primary keys
// https://github.com/doctrine/orm/issues/2910
$paginator = new Paginator($query, 1 === \count($identifierFieldNames));

return $paginator->getIterator();
}

/**
Expand Down
4 changes: 2 additions & 2 deletions tests/Datagrid/ProxyQueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public function testExecuteWithOrderBy(): void
['id' => 2],
['id' => 3],
],
$query->execute()
iterator_to_array($query->execute())
);

$query2 = new ProxyQuery(
Expand All @@ -156,7 +156,7 @@ public function testExecuteWithOrderBy(): void
['id' => 1],
['id' => 3],
],
$query2->execute()
iterator_to_array($query2->execute())
);
}
}

0 comments on commit ae31060

Please sign in to comment.