Skip to content

[Bug]: HasRecordsList breaks custom sorting #23

Description

@Oreo-Monster

What happened?

When sorting by a column that defines a sort query, the HasRecordsList makes an additional query for the ids, but it does not apply the sort function from the column but instead tries to sort with the column name.

How to reproduce the bug

I ran into this while trying to set up sorting by a field on another record.

TextColumn::make('auction_name')
    ->label('Auction')
    ->sortable(query: function(Builder $query, string $direction) {
        $query->withAggregate('Auction', 'name')
            ->orderBy('auction_name');
    }),

When sorting by auction, I get this error:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'auction_name' in 'order clause'
select
id
from
consignments
where
balance_due > 0
and consignments.deleted_at is null
order by
auction_name asc

If I remove the HasRecordsList trait, the error goes away.

Package Version

2.2.2

PHP Version

8.2.27

Laravel Version

10.48.29

Which operating systems does with happen with?

macOS

Notes

No response

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