filament
filament copied to clipboard
Relationship query scopes are not being applied
Package
filament/tables
Package Version
v2.16.8
Laravel Version
v9.31
Livewire Version
No response
PHP Version
PHP 8.1
Problem description
When ordering a table column by a relationship, the relationship scopes are not applied and a
Cardinality violation: 1242 Subquery returns more than 1 row
exception is thrown.
Expected behavior
Sorting works as expected. No exception is thrown
Steps to reproduce
// the Models
class State extends Model
{
use SoftDeletes;
}
class MyModel extends Model
{
public function state(): HasOne
{
return $this->hasOne(State::class);
}
public function allStates(): HasMany
{
return $this->hasMany(State::class)->withTrashed();
}
}
// the Filament Resource
class MyModelResource extends Resource
// ...
public static function table(Table $table): Table
{
return $table
->defaultSort('state.created_at', 'desc')
->columns([
Tables\Columns\TextColumn::make('state.created_at')->sortable(),
// ...
}
}
### Reproduction repository
https://github.com/tiagof/filament-bug-reports/tree/bug/missing-scopes-in-relationship
### Relevant log output
_No response_