I don't understand why the keyword `with` is not working.
Question: https://stackoverflow.com/questions/79409980/keyword-with-is-not-working-with-drizzle
Any idea?
Stack Overflow
Keyword
with
is not working with DrizzleThis is my Drizzle schema:
import { pgTable, text, integer, uuid, timestamp } from "drizzle-orm/pg-core"
import { relations } from "drizzle-orm"
export const userTable = pgTable(&

4 Replies
You need to switch where the "foreign key" is stored. Right now, you should be able to query userCredential with user but not User with UserCredential.
So swap it. Add userCredentialId column to users. And move the Drizzle relation to the user side.
Or I guess make the query from the other side
thanks, but in the documentation, they explicitly say it should work in this direction https://orm.drizzle.team/docs/relations#one-to-one
Like my example, the table
User
does not have the foreign key, but the profile_info
Drizzle ORM - Relations
Drizzle ORM is a lightweight and performant TypeScript ORM with developer experience in mind.

I agree it should work I don't only help with some I'm given though. You didn't indicate any specific error. So I provide the solution of switching.
On Stackoverflow you have a unique constraint on userId but here you don't. So I assume you fixed that issue already
Nope.. this is not solving the issue..