I'm trying using $count, and it giving me fieldAlias missing. What should I do?
I'm on drizzle-orm 0.36.1 and drizzle-kit 0.28.0.
My schema is something like below. For note, its oversimplified over my project.
And my queries is something like this:
Exactly on
historyCount
my editor giving me typescript error something like this:
I enable logger and my raw query is something like this. I make a little modified below, just so the table name will match my example above, everything else is intact
4 Replies
For additional info, I also wrap my query into trycatch and log the error. It throw something like this:
Shouldnt it be
?
You need to do this:
postCount: db.$count(post, eq(post.user, user.id)).as('postCount')
But there's a bug in the $count function see: https://github.com/drizzle-team/drizzle-orm/issues/3493GitHub
[BUG]: db.$count inside relational query "extras" generates SQL wit...
Report hasn't been filed before. I have verified that the bug I'm about to report hasn't been filed before. What version of drizzle-orm are you using? 0.36.0 What version of drizzle-kit...
I make small typo while making this post 🤣, since i'm making brand new example based on my original code.. But I've double check and I'm sure 100% there is no typo on my original code
Adding
as
fixed the issue i encountered. Thanks for the heads up