Missing table alias in query causing error

Not sure if this is a bug or something Wappler can't handle, but I have a fairly simple query where I need to join a table to one of it's own subtables. I have elements that can be a child element of other elements for the layout builder I created with Wappler. However, the table alias appears to be missing in part of the generated Wappler query code and causes an ambiguous error.

{status: "500", code: "ER_NON_UNIQ_ERROR",…}
code
: 
"ER_NON_UNIQ_ERROR"
message
: 
"select `children`.`child_id`, `children`.`child_element_id`, `child_element_table`.`element_name`, `children`.`element_id` as `__dmxForeign` from `element_children` as `children` inner join `elements` as `child_element_table` on `child_element_table`.`element_id` = `children`.`element_id` where `element_id` in ('1') order by `children`.`child_order` ASC - Column 'element_id' in where clause is ambiguous"
stack
: 
"Error: select `children`.`child_id`, `children`.`child_element_id`, `child_element_table`.`element_name`, `children`.`element_id` as `__dmxForeign` from `element_children` as `children` inner join `elements` as `child_element_table` on `child_element_table`.`element_id` = `children`.`element_id` where `element_id` in ('1') order by `children`.`child_order` ASC - Column 'element_id' in where clause is ambiguous\n    at Packet.asError (/opt/node_app/node_modules/mysql2/lib/packets/packet.js:738:17)\n    at Query.execute (/opt/node_app/node_modules/mysql2/lib/commands/command.js:29:26)\n    at Connection.handlePacket (/opt/node_app/node_modules/mysql2/lib/connection.js:481:34)\n    at PacketParser.onPacket (/opt/node_app/node_modules/mysql2/lib/connection.js:97:12)\n    at PacketParser.executeStart (/opt/node_app/node_modules/mysql2/lib/packet_parser.js:75:16)\n    at Socket.<anonymous> (/opt/node_app/node_modules/mysql2/lib/connection.js:104:25)\n    at Socket.emit (node:events:513:28)\n    at addChunk (node:internal/streams/readable:315:12)\n    at readableAddChunk (node:internal/streams/readable:289:9)\n    at Socket.Readable.push (node:internal/streams/readable:228:10)"
status
: 
"500"

I feel like Wappler usually would have the proper alias where I have circled in the screenshot above but it's missing. I tried to go into code view and see if I could figure out where to add it manually but was unsuccessful.

Here is a copy of the api file with the query if that will help the team in trouble shooting.
elements copy.zip (2.8 KB)

Here is a dump of the tables needed for the query.
elements_tables.zip (3.4 KB)

I'd rather not have to create a view or custom query to acheive this cause I feel like I've been able to do similar queries like this with no problem using the Wappler way.

Thanks in advance,
Twitch

Not sure if you use NodeJS for the server, but here an update for the NodeJS version.

dbconnector.zip (3.4 KB) Unzip to lib/modules.

@patrick yes I use NodeJS, thank you, I'll give this a try and let you know. :blush:

-Twitch

You rock @patrick as always. Working like a champ. Thank you!

-Twitch

Fixed in Wappler 7 Release Candidate 4

1 Like