livewire-datatables icon indicating copy to clipboard operation
livewire-datatables copied to clipboard

Finally, Detailed Report on Column Not Found on Export

Open abbasmashaddy72 opened this issue 3 years ago • 10 comments

This Issue Only Occurs when my relation table also has the same column name as that of other related column table

Example: My Table Patient Has a name field column & My Table Locality also Has a name filed column

So at the Time of Export It is Trowing the Error Column not Found

If we fix it Finally, the issue will be solved.

Note: When I am using same relation with count method in number column, it works fine users.name:count Also, It's working fine with relation if all column names are different.

Please Check This Link: https://flareapp.io/share/LPdda1gP#F70

The Above Link will give more Detailed Report on what we are having the issue on Export @marksalmon @thyseus @tomshaw @trippo @renardudezert @mrsid18

abbasmashaddy72 avatar Sep 19 '22 18:09 abbasmashaddy72

Says SQLSTATE[42S22]: Column not found: 1054 Unknown column 'localities.name' in 'field list' Try AS localities_name so not to conflict with users.name.

tomshaw avatar Sep 19 '22 20:09 tomshaw

Says SQLSTATE[42S22]: Column not found: 1054 Unknown column 'localities.name' in 'field list' Try AS localities_name so not to conflict with users.name.

When Using' AS 'as per user suggestion getting this error Error: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'patients.locality.name' in 'field list' Code: Column::name('locality.name as locality_name')

Detailed Report: https://flareapp.io/share/LPdda1gP#F70

From My Point of view We Have to change that in export function. @tomshaw

abbasmashaddy72 avatar Sep 20 '22 04:09 abbasmashaddy72

@abbasmashaddy72 You may have to build your query with a left join.

tomshaw avatar Sep 20 '22 04:09 tomshaw

Okay

It is working fine when I am using join but not when using relationship @tomshaw

abbasmashaddy72 avatar Sep 20 '22 10:09 abbasmashaddy72

@abbasmashaddy72 Currently working weekdays. Checkout src/Http/Livewire/LivewireDatatable.php specifically methods export() and getExportResultsSet() probably an easy fix.

tomshaw avatar Sep 20 '22 11:09 tomshaw

I am on it

abbasmashaddy72 avatar Sep 20 '22 14:09 abbasmashaddy72

The issue is not actually with export but with re-render process. When we run export the query will be built twice. The second time it fails because join is not added. It is not added because second time getSelectStatements function is called columns already have select prop

if ($column->select) { return $column; }

Then as a side effect, resolveColumnName doesn't get called and join is not added.

It is easy to test out, if you delete from a view file the entire html where $this->results is mentioned you will have a table with export button only and export will work. Also if you comment out the part of the code that checks if $column already has select prop set, it will again work (this time both render and export)

I had the same issue and did some debugging to come to this. Maybe I could even prepare a PR, but I need more time to figure out if actually the bug is somewhere else, maybe columns should be reset after certain action? @tomshaw let me know if this rings a bell

kirba avatar Oct 07 '22 22:10 kirba

It is correct, the issue is exactly same

did you find any solution on it @kirba

abbasmashaddy72 avatar Oct 19 '22 11:10 abbasmashaddy72

@abbasmashaddy72

PR #516 should fix it.

As mentioned in the PR, there is a workaround, you can define join clause in builder function and it will be fine

kirba avatar Oct 28 '22 12:10 kirba

Okay Thanks Bro

abbasmashaddy72 avatar Dec 10 '22 12:12 abbasmashaddy72