beberlei/DoctrineExtensions — pull request #51 by sandermarechal (2011-10-10 12:06:24+00:00)
Title: Fixed bug on paginating ORDER BY queries

In some cases, the paginator can give the wrong result or fail when an explicit
ORDER BY clause collides with the field that Paginate is trying to
select in order to limit the query.

Example: User belongsTo group, where group 1 has 4 users. Both User and Group have an id
field. The following DQL will, when paginated, return only a single user and not all 4 users.

SELECT u FROM User u LEFT JOIN u.group g WHERE g.name = 'Some group' ORDER BY g.id ASC

Paginate will issue a select for the User.id but adds the ORDER BY
clause in the result set. But the ScalarHydrator simply overwrites the
User.id with the Group.id, causing the query to fail (or, in the case of
accidentally matching IDs, simply return a single result).

This update ensures that the LimitSubQuery uses unique column aliases to
fix the issue.