FilamentF
Filament13mo ago
nexxai

Error when trying to sort table by MorphTo relationship

I have a table with a model (Person) and that model has a MorphTo relationship type called user(). In generating the table, I'm trying to do the following (some fields removed for the example but they do not matter):
        return $table
            ->columns([
                TextColumn::make('user.name')
                    ->label('Name')
                    ->searchable()
                    ->sortable(),
            ])
            ->defaultSort('name', 'asc')

but when I try to view the table, I get this:
Illuminate \ Database \ QueryException
PHP 8.3.14
11.33.2
SQLSTATE[HY000]: General error: 1 no such column: laravel_reserved_0.
select * from "people" where "people"."deleted_at" is null order by (select "name" from "people" as "laravel_reserved_0" where "laravel_reserved_0"."" = "people"."user_id" and "laravel_reserved_0"."deleted_at" is null) asc limit 10 offset 0

The where "laravel_reserved_0"."" looks suspicious to me (why is the column name blank?), and I suspect it has something to do with the MorphTo relationship, but I'm not clear where to even continue looking and troubleshooting.

I have confirmed:
  • Without the defaultSort(), the table displays the correct user.name value so it's something to do with this call
  • Every Person has a valid
    user_id
    and user_type entry filled in
  • Every referenced
    user_id
    has a valid (non-null)
    name
    value
I'm also having what I think might be a similar issue with the related form for this table; if I try to add live() to the email address field which lives on the same
user
relationship, it doesn't actually fire. I can see the network call to /update happening in the Dev Console, but there's no data in the components.0.effects.returns array which I assume is where any validation errors would otherwise appear?

Is anyone able to give me a hand?
Was this page helpful?