Sortable list column with relation - using old undocumented behavior

I’m having some trouble with undocumented behavior that I’ve occasionally used in my projects.

A) List column can be defined this documented way:

schedule_start:
    relation: schedule
    select: starts_at

In this case, when sorting by the schedule_start column is activated, the entire list is correctly sorted by schedule_start (by the relationship value).

B) List column can be defined this way too:

schedule_name:
    relation: schedule
    valueFrom: name

In this case, when sorting by the schedule_name column is enabled, the entire list is incorrectly sorted by the base table name column (not by the relationship value - the reason is that this value can be result of Eloquent Accessor, not SQL table column!).

C) But nevermind, this behavior is known since version 1. There were/could be hack - using undocumented combination:

schedule_name:
    relation: schedule
    select: starts_at
    valueFrom: name

When sorting by the schedule_name column is enabled, the entire list can be sorted by the selected value (start_at), because this database column is part of the SQL statement, but finally display the relationship value name in the entire list.
I think this hack worked in past, but priority of select and valueFrom was changed and valueFrom is used in sorting instead of select one (so the result is sorting like in example B).

Is it possible to make example C documented and working correct way?

Using valueFrom instructs the list to take the attribute value from the model. IIRC it will disable the select functionality. You could overcome this by using select (and not valueFrom) then setting a partial type. Inside the partial, you can take the “value from” anything you like.

I hope this helps.

Finally I found another solution using event and override value for this special case:

schedule_name:
    relation: schedule
    select: starts_at
    displayFrom: name
$list->bindEvent('list.overrideColumnValue', function ($record, $column, $value) {
    if ($column->columnName == 'schedule_name') {
        return $record->{$column->relation}->{$column->displayFrom};
    }
});

Property displayFrom is quite misused here. Making partial looks to be more clear.
I asked here before this behavior (example C) could be in core somehow, especially for very lazy programmers :slight_smile: