Wappler Version : 3.0.3
Operating System : Windows 10
Expected behavior
This issue seems to be only for queries that have at least 2 tables JOINED in the query and use at least 1 Alias
When you apply dynamic sorting on a table using a DB query, you expect it to work on all columns, even ones that you give an 'Alias' to in the query builder.
Actual behavior
When dynamic sorting is set up, it will only sort on the columns that DO NOT have an alias set up in the query builder.
Any column that you have given an Alias too will not work and will fail with following (extract) message:
order by \"call_types\".\"callName\" desc limit $1 - column call_types.callName does not exist\n at Parser.parseErrorMessage
Where call_types is the table name and "callName" is the Alias
How to reproduce
Create DB query that has at least 2 tables
Give an Alias to half of the columns
Create a table in app connect and apply sortable headers/dynamic sorting as per normal
Test the sorting on the different columns. The ones that use an Alias will NOT work and will cause an error
here is a snapshot of a sample query:
In this example, the sortable headers work fine for item # 3, work_group_id but all ones with an Alias will fail. If this query did not have a join, it would also work, even with the Alias
This looks to still be an issue. I get an error when using an alias, but it sorts OK when using just the column name. I’m using Node JS.
Error: ER_BAD_FIELD_ERROR: Unknown column 'community.community_active' in 'order clause'\n at Query.Sequence._packetToError
I have some functions on the page that don’t work using the column name as ‘active’ in the query. For example this:
Make {{active==1?'Inactive':'Active'}}
will only ever return ‘Make Active’ whereas this:
Make {{community_active==1?'Inactive':'Active'}}
toggles Active/Inactive as expected. I assume using active is conflicting somewhere.
Would be really useful to know if the sorting by alias is fixable, I have the same column name and behaviours in a range of tables. If it’s not I can change the column names in the DB and related queries, but it would be preferable to be able to use an alias!
I’m suddenly getting this as well in v5.8.2 Odd thing is, it’s not doing it in my dev environment but on production. I’m wondering if I haven’t uploaded an updated wappler file that handles the sorting. Not sure which one it would be though.
Just ran in to this, look like still not fixed, standard bootstrap 5 table with generator and query manager sorting. The generator set the sorting to the alias of course but gives a server 500 error as the column does not exist. Let me know if you need more info/screenshots etc.
I haven’t looked into this in a while, I probably just had to turn sorting off etc.
But if you need it, something I think would work (and also if you want to use pagination with a custom query) is to write the query as a View in your DB. Then you can access it as Wappler as a simple query without changes.
I use Postgres so not sure if others have Views.
I figured this would work with any complex query where you’d want to take advtage of some Wapplers built in features such as the aforementioned Pagination.