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

Reset order by before count(). #60

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

StyxOfDynamite
Copy link

@StyxOfDynamite StyxOfDynamite commented Jul 18, 2022

This PR addresses my comment on #56

In my case, a select column exist that applies an alias, that alias is then used in the orderBy, when fetching a count() query, the select columns are rewritten, but not the orderBy that references them.


if (empty($this->groups)) {
$without['orders'] = [];
}
Copy link
Author

@StyxOfDynamite StyxOfDynamite Jul 19, 2022

Choose a reason for hiding this comment

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

This is the only real code change, the rest was generated by applying the diff supplied by Style CI.
There is also a change to the tests I've highlighted further down.

@@ -703,7 +703,7 @@ public function test_count()
$this->assertEquals('SELECT count() as `count` FROM `table`', $builder->toSql());

$builder = $this->getBuilder()->from('table')->select('column1', 'column2', 'column3')->groupBy('column2')->orderBy('column1')->limit(10)->getCountQuery();
$this->assertEquals('SELECT count() as `count` FROM `table` GROUP BY `column2` ORDER BY `column1` ASC', $builder->toSql());
$this->assertEquals('SELECT count() as `count` FROM `table` GROUP BY `column2`', $builder->toSql());
Copy link
Author

Choose a reason for hiding this comment

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

This change updates the test so as not to check for ORDER BY when doing a count()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant