Sortable - Sort by far relationship

I have model A Which has a relationship with a pivot, model B The pivot has a relationship with another model, model C In my filament table, which has model A as model for the query, I try to sort by an attribute of the model C
Tables\Columns\TextColumn::make('modelB.modelC.date')
->date('d/m/Y H:i')
->sortable(),
Tables\Columns\TextColumn::make('modelB.modelC.date')
->date('d/m/Y H:i')
->sortable(),
but i get:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'modelB_tablename.modelC.id' in 'where clause'
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'modelB_tablename.modelC.id' in 'where clause'
1 Reply
ericmp #2
ericmp #212mo ago
is it possible to sort it like this? then, to try to solve it i updated the sortable function:
->sortable(query: function (Builder $query, string $direction): Builder {
return $query->whereHas('modelB', function ($q) use ($direction) {
$q->whereHas('modelC', function ($q2) use ($direction) {
$q2->orderBy('date', $direction);
});
});
})
->sortable(query: function (Builder $query, string $direction): Builder {
return $query->whereHas('modelB', function ($q) use ($direction) {
$q->whereHas('modelC', function ($q2) use ($direction) {
$q2->orderBy('date', $direction);
});
});
})
like this doesnt crash, but doesnt work neither