Skip to content

Commit

Permalink
Fix Ticket #6 and #3
Browse files Browse the repository at this point in the history
  • Loading branch information
beberlei committed Aug 31, 2010
1 parent a1657f0 commit ddc8a18
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/DoctrineExtensions/Paginate/CountWalker.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,8 @@ public function walkSelectStatement(SelectStatement $AST)
new AggregateExpression('count', $pathExpression, true), null
)
);

// ORDER BY is not needed, only increases query execution through unnecessary sorting.
$AST->orderByClause = null;
}
}
15 changes: 15 additions & 0 deletions tests/DoctrineExtensions/Paginate/CountWalkerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,18 @@ public function testCountQuery()
);
}

public function testCountQuery_RemovesOrderBy()
{
$query = $this->entityManager->createQuery(
'SELECT p, c, a FROM DoctrineExtensions\Paginate\BlogPost p JOIN p.category c JOIN p.author a ORDER BY a.name');
$countQuery = Paginate::createCountQuery($query);

$this->assertEquals(
"SELECT count(DISTINCT b0_.id) AS sclr0 FROM BlogPost b0_ INNER JOIN Category c1_ ON b0_.category_id = c1_.id INNER JOIN Author a2_ ON b0_.author_id = a2_.id",
$countQuery->getSql()
);
}

public function testCountQuery_RemovesLimits()
{
$query = $this->entityManager->createQuery(
Expand Down Expand Up @@ -75,6 +87,9 @@ class Author
{
/** @Id @column(type="integer") @generatedValue */
public $id;

/** @Column(type="string") */
public $name;
}

/**
Expand Down

0 comments on commit ddc8a18

Please sign in to comment.