Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Doctrine][Pagination] Complex OrderBy item must use output walker #1313

Closed
teohhanhui opened this issue Aug 11, 2017 · 7 comments
Closed

[Doctrine][Pagination] Complex OrderBy item must use output walker #1313

teohhanhui opened this issue Aug 11, 2017 · 7 comments
Assignees
Labels

Comments

@teohhanhui
Copy link
Contributor

The results are wrong for example when ordering by a result variable.

https://github.com/doctrine/doctrine2/blob/e6c434196c8ef058239aaa0724b4aadb0107940b/lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryWalker.php#L141

@teohhanhui teohhanhui added the bug label Aug 11, 2017
@soyuka
Copy link
Member

soyuka commented Aug 11, 2017

Needs a change in our QueryChecker?

Feel free to continue on #1301

@teohhanhui
Copy link
Contributor Author

The bigger issue is that it might be unsafe in many cases to not use the output walkers, but we do not know. The only symptom may be incorrect paginated results.

@ambroisemaupate
Copy link
Contributor

Hello,

I’ve got the same issue with this DQL (Cannot select distinct identifiers from query with LIMIT and ORDER BY on a column from a fetch joined to-many association. Use output walkers) :

SELECT o FROM AppBundle\Entity\Event o 
INNER JOIN o.dates dates_a1 
WHERE o.superEvent IS NULL 
ORDER BY dates_a1.doorTime DESC

This is generated for this request: {{url}}/events?order[dates.doorTime]=DESC

I’ve found that method QueryChecker::hasOrderByOnToManyJoin($queryBuilder, $this->managerRegistry) returns false but it should return true.

@soyuka
Copy link
Member

soyuka commented Oct 2, 2017

9f9da0c last fix on the subject. Please help improving this!

@rlanting-move
Copy link

I’ve found that method QueryChecker::hasOrderByOnToManyJoin($queryBuilder, $this->managerRegistry) returns false but it should return true.

It returns false because on QueryChecker.php#L153 $metadata is the joined entity and on QueryChecker.php#L154 $relationship is 'o.joinedEntity'. There is never a field that has a dot in it, and even if there would be, it checks on the wrong metadata.

I did a quick fix with the old code to see whether everything would work and it did. Basically did this:

...
if (false !== strpos($relationship, '.')) {
    list($parentAlias, $association) = explode('.', $relationship);

    $parentMetadata = QueryJoinParser::getClassMetadataFromJoinAlias($parentAlias, $queryBuilder, $managerRegistry);
    if ($parentMetadata->isCollectionValuedAssociation($association)) {
        return true;
    }
} else {
...

This does not handle deeper associations, but I don't know whether that is needed. If @soyuka could look into this, that would be awesome.

@soyuka soyuka self-assigned this Oct 5, 2017
@ambroisemaupate
Copy link
Contributor

@rlantingmove4mobile fix works for me.

ambroisemaupate added a commit to rezozero/core that referenced this issue Oct 10, 2017
@soyuka
Copy link
Member

soyuka commented Oct 11, 2017

@ambroisemaupate would you mind sending a PR with your referenced commit?

meyerbaptiste pushed a commit to rezozero/core that referenced this issue Nov 2, 2017
meyerbaptiste pushed a commit to rezozero/core that referenced this issue Nov 2, 2017
soyuka pushed a commit to soyuka/core that referenced this issue Nov 2, 2017
@soyuka soyuka closed this as completed Nov 3, 2017
hoangnd25 pushed a commit to hoangnd25/core that referenced this issue Feb 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants