irsyadulibad / ci4-datatables

Server Side Datatables Library for CodeIgniter 4 Framework
https://ci4-datatables.netlify.app
MIT License
72 stars 32 forks source link

Problem with join when tables have same column name #12

Closed jroaes closed 3 years ago

jroaes commented 3 years ago

I tried this

return DataTables::use('users_mobile')
            ->select('users_mobile.id, users_mobile.name as user_name, users_mobile.rut, users_mobile.platform, area.name as area_name')
            ->join('area', 'area.id = users_mobile.area_id')
            ->hideColumns(['users_mobile.id'])
            ->rawColumns(['action'])
            ->make(true);

but when load the page, show me alert error. When I see the php url I see a error, and was this: mysqli_sql_exception #1052 Column 'name' in where clause is ambiguous

And the code when this happened is in: VENDORPATH\irsyadulibad\codeigniter4-datatables\src\TableProcessor.php : 35

is there a way to fix this without having to change the column name?

(Sorry for my bad english, is not my language)

irsyadulibad commented 3 years ago

Why not just use an aliases? I thought, that would be better than using the same field names

jroaes commented 3 years ago

I'm using aliases: users_mobile.name as user_name area.name as area_name

But is not working when load the page. Only work when load the "get" url without param's, but datatable ajax include a lot of params. When include the param's the SQL generated by library not considered the aliases, just it's take the real name not the aliases

irsyadulibad commented 3 years ago

Sorry for the long response, I have updated the library to overcome this problem. The library will automatically select a column in the primary table if there are columns that have not been aliased irsyadulibad/ci4-datatables@0c914084efb69caec7c61d65246fcc01cb9c0915