Closed
Description
Summary of problem or feature request
Displaying list of records from Pivot Table works. Basic example with a belongsToMany in the model.
$model->abilities();
public function abilities()
{
return $this->belongsToMany(Ability::class);
}
Add orderBy results in duplicate column error. The Pivot Table has timestamp columns.
$model->abilities()->orderBy('ability.name');
error: "Exception Message:\n\nSQLSTATE[42S21]: Column already exists: 1060 Duplicate column name 'created_at' (SQL: select count(*) as aggregate from (select * from
abilities
inner joinability_role
onabilities
.id
=ability_role
.ability_id
whereability_role
.role_id
= 2 order byabilities
.name
asc) count_row_table)"
The same command executes properly in Tinkerwell / Laravel Controller. But not via laravel-datatables. Maybe related to #1739 ?
Quick fix for me was to add a select to exclude the created_at + updated_at columns.
$model->abilities()->select('id','name','label')->orderBy('ability.name');
System details
- Operating System: WAMPSERVER
- PHP Version: 8.0.11
- Laravel Version: 8.68.1
- Laravel-Datatables Version: 9.18.2