Merge pull request #640 from denkiryokuhatsuden/patch-1
[Paginator]Add hidden field ordering for postgresql
This commit is contained in:
commit
20e5d98b7b
@ -92,8 +92,26 @@ class LimitSubqueryOutputWalker extends SqlWalker
|
|||||||
*/
|
*/
|
||||||
public function walkSelectStatement(SelectStatement $AST)
|
public function walkSelectStatement(SelectStatement $AST)
|
||||||
{
|
{
|
||||||
|
if ($this->platform instanceof PostgreSqlPlatform) {
|
||||||
|
// Set every select expression as visible(hidden = false) to
|
||||||
|
// make $AST to have scalar mappings properly
|
||||||
|
$hiddens = array();
|
||||||
|
foreach ($AST->selectClause->selectExpressions as $idx => $expr) {
|
||||||
|
$hiddens[$idx] = $expr->hiddenAliasResultVariable;
|
||||||
|
$expr->hiddenAliasResultVariable = false;
|
||||||
|
}
|
||||||
|
|
||||||
$innerSql = parent::walkSelectStatement($AST);
|
$innerSql = parent::walkSelectStatement($AST);
|
||||||
|
|
||||||
|
// Restore hiddens
|
||||||
|
foreach ($AST->selectClause->selectExpressions as $idx => $expr) {
|
||||||
|
$expr->hiddenAliasResultVariable = $hiddens[$idx];
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$innerSql = parent::walkSelectStatement($AST);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Find out the SQL alias of the identifier column of the root entity.
|
// Find out the SQL alias of the identifier column of the root entity.
|
||||||
// It may be possible to make this work with multiple root entities but that
|
// It may be possible to make this work with multiple root entities but that
|
||||||
// would probably require issuing multiple queries or doing a UNION SELECT.
|
// would probably require issuing multiple queries or doing a UNION SELECT.
|
||||||
|
@ -74,6 +74,25 @@ class LimitSubqueryOutputWalkerTest extends PaginationTestCase
|
|||||||
$this->entityManager->getConnection()->setDatabasePlatform($odp);
|
$this->entityManager->getConnection()->setDatabasePlatform($odp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testLimitSubqueryWithHiddenScalarSortPg()
|
||||||
|
{
|
||||||
|
$odp = $this->entityManager->getConnection()->getDatabasePlatform();
|
||||||
|
$this->entityManager->getConnection()->setDatabasePlatform(new \Doctrine\DBAL\Platforms\PostgreSqlPlatform);
|
||||||
|
|
||||||
|
$query = $this->entityManager->createQuery(
|
||||||
|
'SELECT u, g, COUNT(g.id) AS hidden g_quantity FROM Doctrine\Tests\ORM\Tools\Pagination\User u JOIN u.groups g ORDER BY g_quantity, u.id DESC'
|
||||||
|
);
|
||||||
|
$limitQuery = clone $query;
|
||||||
|
$limitQuery->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, 'Doctrine\ORM\Tools\Pagination\LimitSubqueryOutputWalker');
|
||||||
|
|
||||||
|
$this->assertEquals(
|
||||||
|
"SELECT DISTINCT id1, sclr0 FROM (SELECT COUNT(g0_.id) AS sclr0, u1_.id AS id1, g0_.id AS id2 FROM User u1_ INNER JOIN user_group u2_ ON u1_.id = u2_.user_id INNER JOIN groups g0_ ON g0_.id = u2_.group_id ORDER BY sclr0 ASC, u1_.id DESC) dctrn_result ORDER BY sclr0 ASC, id1 DESC",
|
||||||
|
$limitQuery->getSql()
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->entityManager->getConnection()->setDatabasePlatform($odp);
|
||||||
|
}
|
||||||
|
|
||||||
public function testLimitSubqueryPg()
|
public function testLimitSubqueryPg()
|
||||||
{
|
{
|
||||||
$odp = $this->entityManager->getConnection()->getDatabasePlatform();
|
$odp = $this->entityManager->getConnection()->getDatabasePlatform();
|
||||||
|
Loading…
Reference in New Issue
Block a user