Skip to content

Commit

Permalink
Merge pull request #65 from sschuster/main
Browse files Browse the repository at this point in the history
Fixing Query expressions as orderBy clauses
  • Loading branch information
aarondfrancis authored May 16, 2024
2 parents a4bf5cf + d364b21 commit 6a1fb26
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/FastPaginate.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ public static function getInnerSelectColumns($builder)
// is totally reasonable. We'll look for both
// quoted and unquoted, as a kindness.
// See https://github.com/hammerstonedev/fast-paginate/pull/57
$column = $column instanceof Expression ? $column->getValue($base->grammar) : $column;

return [
$column,
$base->grammar->wrap($column),
Expand Down
15 changes: 15 additions & 0 deletions tests/Integration/BuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,21 @@ public function unquoted_selects_are_preserved_if_used_in_order_by()
);
}

/** @test */
public function using_expressions_for_order_work()
{
$queries = $this->withQueriesLogged(function () use (&$results) {
$results = User::query()->selectRaw('(select 1) as computed_column')->orderBy(
User::query()->select('name')->orderBy('name')->limit(1)->getQuery()
)->fastPaginate();
});

$this->assertEquals(
'select `users`.`id` from `users` order by (select `name` from `users` order by `name` asc limit 1) asc limit 15 offset 0',
$queries[1]['query']
);
}

/** @test */
public function havings_defer()
{
Expand Down

0 comments on commit 6a1fb26

Please sign in to comment.