Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Paginator OrderBy fix take 2#1337

Merged
Ocramius merged 6 commits into
doctrine:masterfrom
billschaller:paginator-orderby-fix
Mar 24, 2015
Merged

Paginator OrderBy fix take 2#1337
Ocramius merged 6 commits into
doctrine:masterfrom
billschaller:paginator-orderby-fix

Conversation

@billschaller
Copy link
Copy Markdown
Member

This PR fixes issues created in #1220, reported in #1267. The original PR was reverted in #1283.

The issue was that in queries ordered by joined association columns, the joined column aliases did not exist in the outer query created in LimitSubqueryOutputWalker.

This PR adds functionality to LimitSubqueryOutputWalker which finds any such columns referenced in the OrderBy clause, and adds them to the SelectStatement prior to SQL generation.

@doctrinebot
Copy link
Copy Markdown

Hello,

thank you for creating this pull request. I have automatically opened an issue
on our Jira Bug Tracker for you. See the issue link:

http://www.doctrine-project.org/jira/browse/DDC-3623

We use Jira to track the state of pull requests and the versions they got
included in.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use named subpatterns if possible

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm this is public API. Can we really change method signature and return type here?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably be private.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Making it private on merge.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not quite sure if this does any harm to non SQL Server platforms which actually support ORDER BY clauses in subqueries. This might change results, no? So an option could be to throw an exception for SQL Server or just ignore the ORDER BY as done here. Please correct me if I'm wrong here...

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

essentially an order by clause in a subquery without a limit applied is meaningless - there may be scenarios where ordering by in a subquery can be implemented by a DBA to help with joins on subordinate keys, but the ORM doesn't do that.

@raziel057
Copy link
Copy Markdown
Contributor

Is this ticket related to this one? #1151

@billschaller
Copy link
Copy Markdown
Member Author

@guilhermeblanco fixed capitalization

@billschaller
Copy link
Copy Markdown
Member Author

@raziel057 I believe this should fix #1151

@raziel057
Copy link
Copy Markdown
Contributor

@zeroedin-bill Ok thanks. I can check if the bug is fixed as soon as the PR is merged.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are you adding an extra argument compared to the walker API ? this looks wrong to me (and it can cause issues later).

The logic needing to be shared between 2 cases should be extracted to a separate method and the case of addMissingItemsFromOrderByToSelect should use another method than walkSelectStatement for the case it needs a separate logic

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason for this is because the walker clones itself and then calls walkSelectStatement on the clone. The method that does the cloning and that nonsense is called from walkSelectStatement. Not sure how better to structure that call chain so as to avoid recursion and still allow the functionality.

I'm open to suggestions...

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stof would it make sense to move the body of walkSelectStatement to a separate method, say doWalkSelectStatement(SelectStatement $AST, $addMissingItemsFromOrderByToSelect) and then have the main walkSelectStatement method just call that? Not sure that obfuscation would help anything but it does resolve the function signature weirdness.

Ocramius added a commit that referenced this pull request Mar 24, 2015
…sues' into hotfix/#1342-paginator-functional-test-integration
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants