aarondfrancis / fast-paginate

A fast implementation of offset/limit pagination for Laravel.
MIT License
1.21k stars 56 forks source link

Subqueries in orderBy broken since 1.1.0 #66

Closed sschuster closed 5 months ago

sschuster commented 5 months ago

Hi @aarondfrancis. Thanks for this package.

Unfortunately since the 1.1.0 release we found a problem with our queries. We use subqueries for orders for more complex scenarios (see example in my test in https://github.com/hammerstonedev/fast-paginate/pull/65). The change to allow custom selects in combination with Expressions as orders clashes.

I'm not sure I understand why you double the order columns with wrapped and unwrapped versions:

return [
    $column,
    $base->grammar->wrap($column)
];

But the unwrapped version didn't work if it is an expression. I added the check and conversion for that as well as a test (sry for the stupid order by - as said in reality it's used for more complex scenarios). Also the test for custom select https://github.com/hammerstonedev/fast-paginate/pull/57 still works.

Here is my PR: https://github.com/hammerstonedev/fast-paginate/pull/65

Thanks for considering.

aarondfrancis commented 5 months ago

Nice catch! Thank you so much.