Inner joining and left joining the same table (aliased) causes the return type to be never
I'm getting a weird issue where if I make two table aliases for the same table and then inner join one while left joining the other, the return type of my query ends up being
never[]
.
Unfortunately the type of data becomes:
I've reduced the Company table to the smallest it could possibly be but it makes absolutely no difference:
Interestingly, if both joins to the Company
table are left joins or if both joins are inner joins, it works fine, but that's not my intended behavior.
What am I missing here? 🤔13 Replies
Another note is that, types aside, my query works as intended with one inner join and one left join.
Having the exact same error! Did you find a solution for it? It seems that it does work in runtime, so the sql is generated correctly, but the types are
never[]
.
I fixed it by just leftJoin
ing both aliases.Unfortunately had to do the same.
+1
@Ian Schoen Hi there, could you file an issue on Github providing the same details as you did above? Want to keep track of this as it seems like an important thing to fix.
I had the same thought just a few days ago. Can do.
Thanks! We'll look into solving this as soon as we can
I'm not sure if could be related but I was doing some
db.select({...geColumns(tableA), ...getColumns(tableB)})
and result wasnt expected as table fields overlap
solution was do an object
This is intentional behavior due to how objects work in JS/TS, the keys from the 2nd object being spread will override any that are also present in the 1st
ye ye, I know, but it wasnt so clear as examples had just 1 field override and I need to keep everything else as it was, tbh it would be usefull if there was a way to extend the select() behavour without instead of override it as you need to define every single column then
atlesat when I tried I couldnt pass an alias to select is that correct?
you can fix the issue by doing this:
what I did was group them like:
Idially I would like to keep select() behavour and just add the extra cols that what I mean but didnt found a quick way to have taht without table: getColumns(table) for each table involve in the query
We just closed the related open issue: https://github.com/drizzle-team/drizzle-orm/issues/2989
The fix is simply to use
alias
instead of aliasedTable
.GitHub
[BUG]: Aliasing the same table twice and then inner joining one whi...
What version of drizzle-orm are you using? 0.31.1 What version of drizzle-kit are you using? No response Describe the Bug If I make two table aliases for the same table and then inner join one whil...