Laravel-datatables: Problem sorting after upgrading to 8.x

Created on 31 Aug 2017  路  3Comments  路  Source: yajra/laravel-datatables

After upgrading to laravel-datatables 8 and datatables.net 1.10.15 I have problems with ordering a column. I use several joins to get my data which creates the situation that certain column names become ambiguous when querying without the table name.

I try to sort on the created_at column on the students table.

My backend code:

$students = Students::join(... // join all tables

$students->select('students.created_at', // ... other columns, etc.

return \Datatables::of($students)
            ->editColumn('students.created_at', '{!! \Carbon\Carbon::parse($created_at)->toDateString() !!}') 
            ->make(TRUE);

Front-end code:

columns: [
            {data: 'created_at', name: 'students.created_at'},
            // other columns

When sorting on created_at I get the error:

Exception Message:鈫碘喌SQLSTATE[HY000]: General error: 1 ambiguous column name: created_at (SQL: select "students"."created_at", etc...

and the query ends with order by "created_at" desc.

Why does the order function remove the table name when creating the query?

  • Windows 10
  • PHP 7.1
  • Laravel 5.5
  • Laravel-Datatables 8.0.0
bug

All 3 comments

It seems like the current version always assumes that a column name with 2 or more parts uses eager loading.

Will send a patch to fix this. Thanks for reporting.

Patch released on v8.0.1. Kindly update again and confirm. Thanks!

I can confirm that v8.0.1 works as expected, thanks for the quick response!

Was this page helpful?
0 / 5 - 0 ratings