[V5] How to add an alias on a Lucid query #1949
douglasdnzcarvalho
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Basically, I have three tables: tableA, tableB and tableC (which is a pivot table). Im trying to make a query on tableA searching for records that are not present in the tableC based on a key from tableB. The function bellow works and returns a json array (as expected) in the data property:
The problem is that I actually need to return a Lucid Model array cause I will use it to make some calculations and updates later, and the fields mapping is important to the final result.
I've tried change the lines
Database.query().from(`${TableA.table} as a`)
toTableA.query().as('a')
but it gives me this error:select count(*) as "total" from "tablea" where not exists (select "c"."tablea_id" from "tablec" as "c" where c.tablea_id = a.id and "c"."tableb_id" = $1) - missing FROM-clause entry for table "a"
Apparently the as() function is not being executed. Would anyone have any suggestions to solve the problem?
Beta Was this translation helpful? Give feedback.
All reactions