Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem sorting after upgrading to 8.x #1353

Closed
marijnhurkens opened this issue Aug 31, 2017 · 3 comments
Closed

Problem sorting after upgrading to 8.x #1353

marijnhurkens opened this issue Aug 31, 2017 · 3 comments
Labels

Comments

@marijnhurkens
Copy link

marijnhurkens commented Aug 31, 2017

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
@yajra yajra added the bug label Aug 31, 2017
@yajra
Copy link
Owner

yajra commented Aug 31, 2017

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.

@yajra
Copy link
Owner

yajra commented Aug 31, 2017

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

@marijnhurkens
Copy link
Author

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

@github-actions github-actions bot locked and limited conversation to collaborators Oct 27, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants