© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•2y ago•
4 replies
spacedev

Issue with ExportAction on table with defaultSort() on a relationship attribute

Hello,

while trying to export this table data we get this error:

Next Illuminate\Database\QueryException: SQLSTATE[42P10]: Invalid column reference: 7 ERROR:  SELECT DISTINCT ON expressions must match initial ORDER BY expressions
LINE 1: select distinct on ("reseller_prices"."id") * from "reseller_prices" where "reseller_prices"."rate_reseller_id" = 2 and "reseller_prices"."rate_reseller_id" is not null order by (select "destination" from "destinations" where "reseller_prices"."destination_id" = "destinations"."id") asc limit 100 offset 0
Next Illuminate\Database\QueryException: SQLSTATE[42P10]: Invalid column reference: 7 ERROR:  SELECT DISTINCT ON expressions must match initial ORDER BY expressions
LINE 1: select distinct on ("reseller_prices"."id") * from "reseller_prices" where "reseller_prices"."rate_reseller_id" = 2 and "reseller_prices"."rate_reseller_id" is not null order by (select "destination" from "destinations" where "reseller_prices"."destination_id" = "destinations"."id") asc limit 100 offset 0


Are we missing something or is this a BUG? Thanks
This is our code (Models involved and Resource Table).

class ResellerPrice extends Model
{
    use HasFactory;

    /**
     * The attributes that aren't mass assignable.
     *
     * @var array
     */
    protected $guarded = [];

    public function destination(): BelongsTo {
        return $this->belongsTo(Destination::class);
    }
}
class ResellerPrice extends Model
{
    use HasFactory;

    /**
     * The attributes that aren't mass assignable.
     *
     * @var array
     */
    protected $guarded = [];

    public function destination(): BelongsTo {
        return $this->belongsTo(Destination::class);
    }
}


public function table(Table $table): Table
{
    return $table
        ->recordTitleAttribute('id')
        ->columns([
            TextColumn::make('destination.destination')
                ->sortable(),
            TextColumn::make('destination.description')
                ->sortable(),
            TextColumn::make('price'),
            TextColumn::make('connection_charge'),
            TextColumn::make('billing_increment')
        ])
        ->defaultSort('destination.destination')
        ->filters([
            //
        ])
        ->headerActions([
            ExportAction::make()
                ->exporter(ResellerPriceExporter::class)
                ->formats([
                    ExportFormat::Xlsx,
                    ExportFormat::Csv,
                ]),
        ])
        ->actions([
            //
        ])
        ->bulkActions([
            //
        ]);
    }
}
public function table(Table $table): Table
{
    return $table
        ->recordTitleAttribute('id')
        ->columns([
            TextColumn::make('destination.destination')
                ->sortable(),
            TextColumn::make('destination.description')
                ->sortable(),
            TextColumn::make('price'),
            TextColumn::make('connection_charge'),
            TextColumn::make('billing_increment')
        ])
        ->defaultSort('destination.destination')
        ->filters([
            //
        ])
        ->headerActions([
            ExportAction::make()
                ->exporter(ResellerPriceExporter::class)
                ->formats([
                    ExportFormat::Xlsx,
                    ExportFormat::Csv,
                ]),
        ])
        ->actions([
            //
        ])
        ->bulkActions([
            //
        ]);
    }
}
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

Table ExportAction failing on relationship
FilamentFFilament / ❓┊help
2y ago
table ->defaultSort()
FilamentFFilament / ❓┊help
12mo ago
how add defaultSort('') with relationship
FilamentFFilament / ❓┊help
3y ago
Grouping by a relationship attribute issue (V4)
FilamentFFilament / ❓┊help
6mo ago