Skip to content

Cursor Pagination in conjunction with subqueries in order by #95

@MKodde

Description

@MKodde

Thanks

Let me start by saying: thank you for this great library. I've been using it for the last couple of weeks and it prevented me from writing sort and filter logic for my project for the nth time!

The issue

I did however run into some complications while sorting on a join column. The Purity sorting component quite nicely created a sub query in the order by clause. Causing the dataset to be correctly sorted on the name field of a related table.

However, when going to the next page of my data set (utilizing the cursor pagination implementation shipped with illuminate). The resulting data set was not compatible with the cursor pagination, and a 500 error is thrown when the pagination UI components are created. Specifically, the call to the flip method errors, because the registered order by parts of the query builder contain non string arguments. (It contains the sub query expression).

To illustrate why the framework is not able to apply the cursor pagination: The exact issue that I ran into was already posted as an issue at the Laravel boards: laravel/framework#38447. They are not going to support this, as cursor pagination needs a result set of unique values, and including a sub query does not ensure that.

Proposed solution

The solution (in my opinion) would be to change the way the Sort component creates his query parts. I would suggest to create join's to the related tables instead of using a sub query.

Before I start putting a PR together, can you elaborate if this would be OK, and if this would be at all possible?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions