We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
drizzle-orm
0.35.1
drizzle-kit
0.26.2
I was trying to implement the new count API following the example from the release notes:
await ctx.db.query.customers.findMany({ extras: { tasksCount: ctx.db .$count( tasks, eq(tasks.customerId, customers.id), ) .as("tasksCount"), }, });
However, this resulted in the following subquery: (select count(*) from "tasks" where "customers"."customer_id" = "customers"."id")
(select count(*) from "tasks" where "customers"."customer_id" = "customers"."id")
and inevitably gave this error:
"Unknown column 'customers.customer_id' in 'where clause'"
This is quite confusing, and perhaps a bit misleading because you'd assume that tasks.customerId would mean the customer id from the tasks table.
tasks.customerId
To get it to work I had to change it to this:
tasksCount: ctx.db .$count( tasks, sql`\`tasks\`.\`customer_id\` = \`customers\`.\`id\``, ) .as("tasksCount"),
When you import a table and use it in a where clause it should take into account the table name, not just the column name.
For example:
eq(tasks.customerId, customers.id)
should be equivalent to
sql`\`tasks\`.\`customer_id\` = \`customers\`.\`id\`
No response
The text was updated successfully, but these errors were encountered:
No branches or pull requests
What version of
drizzle-orm
are you using?0.35.1
What version of
drizzle-kit
are you using?0.26.2
Describe the Bug
I was trying to implement the new count API following the example from the release notes:
However, this resulted in the following subquery:
(select count(*) from "tasks" where "customers"."customer_id" = "customers"."id")
and inevitably gave this error:
"Unknown column 'customers.customer_id' in 'where clause'"
This is quite confusing, and perhaps a bit misleading because you'd assume that
tasks.customerId
would mean the customer id from the tasks table.To get it to work I had to change it to this:
Expected behavior
When you import a table and use it in a where clause it should take into account the table name, not just the column name.
For example:
should be equivalent to
sql`\`tasks\`.\`customer_id\` = \`customers\`.\`id\`
Environment & setup
No response
The text was updated successfully, but these errors were encountered: