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 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); } } 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([ // ]); } }
3 Replies
magicboi69
magicboi699mo ago
hey! same problem here, but without defaultsort and it happens when you change the column sorting feels like a bug to me, maybe the best bet for now is to use a plugin 🤔
Dr_DinoMight
Dr_DinoMight9mo ago
Hi sorry to bring up this old post, but did you manage to get to the bottom of this? I've hit the same issue on two reports, I'm trying to export. I have managed to replicate both with having a defaultSort and clicking on a column to provide a order. Apart from using a diffrent resource and model name, I pretty much have the same setup.
spacedev
spacedevOP9mo ago
Hi, no I didn't find a solution yet
Want results from more Discord servers?
Add your server