diff --git a/src/FastPaginate.php b/src/FastPaginate.php index 2c73821..758ae90 100644 --- a/src/FastPaginate.php +++ b/src/FastPaginate.php @@ -117,10 +117,16 @@ public static function getInnerSelectColumns($builder) ->pluck('column') ->filter() ->map(function ($column) use ($base) { - // Use the grammar to wrap them, so that our `str_contains` - // (further down) doesn't return any false positives. - return $base->grammar->wrap($column); - }); + // Not everyone quotes their custom selects, which + // is totally reasonable. We'll look for both + // quoted and unquoted, as a kindness. + // See https://github.com/hammerstonedev/fast-paginate/pull/57 + return [ + $column, + $base->grammar->wrap($column) + ]; + }) + ->flatten(1); return collect($base->columns) ->filter(function ($column) use ($orders, $base) { diff --git a/tests/Integration/BuilderTest.php b/tests/Integration/BuilderTest.php index 8ff8aee..f5e1b7a 100644 --- a/tests/Integration/BuilderTest.php +++ b/tests/Integration/BuilderTest.php @@ -205,27 +205,14 @@ public function selects_are_overwritten() } /** @test */ - public function selects_are_preserved_if_used_in_order_by() + public function unquoted_selects_are_preserved_if_used_in_order_by() { $queries = $this->withQueriesLogged(function () use (&$results) { - $results = User::query()->selectRaw('(select 1 as computed_column)')->orderBy('computed_column')->fastPaginate(); + $results = User::query()->selectRaw('(select 1) as computed_column')->orderBy('computed_column')->fastPaginate(); }); $this->assertEquals( - 'select `users`.`id`, (select 1 as computed_column) from `users` order by `computed_column` asc limit 15 offset 0', - $queries[1]['query'] - ); - } - - /** @test */ - public function selects_are_preserved_if_used_in_where_constraint() - { - $queries = $this->withQueriesLogged(function () use (&$results) { - $results = User::query()->selectRaw('(select 1 as computed_column)')->where('computed_column', 1)->fastPaginate(); - }); - - $this->assertEquals( - 'select `users`.`id`, (select 1 as computed_column) from `users` where `computed_column` = 1 asc limit 15 offset 0', + 'select `users`.`id`, (select 1) as computed_column from `users` order by `computed_column` asc limit 15 offset 0', $queries[1]['query'] ); }