Naresh Bhatia
10/29/2021, 2:22 AMRyan
10/29/2021, 7:09 AMRyan
10/29/2021, 7:10 AMNaresh Bhatia
10/29/2021, 2:50 PMCREATE TABLE "User" (
id SERIAL PRIMARY KEY
);
CREATE TABLE "Profile" (
id SERIAL PRIMARY KEY,
FOREIGN KEY ("id") REFERENCES "User"(id)
);
So the User table entry might look like:
id: "a12-b23-c45", name: "John Smith"
and the corresponding profile entry might look like:
id: "a12-b23-c45", picture: "https://....."
In other words, the PK on both tables has the same value.Naresh Bhatia
10/30/2021, 4:55 AMmodel User {
id String @id @default(uuid())
name String
}
model Profile {
id String @id
picture String
}
and use it like this:
// Create a User
const user = prisma.user.create({
data: { name: 'John Smith' }
})
// Create a profile for the user
// Note that profile.id = user.id
const profile = prisma.profile.create({
data: { id: user.id, picture: 'https://...' }
})
Is there any downside to this approach? Of course, I am not telling Prisma that there is a one-to-one relationship. So maybe the query to fetch a user's profile will be more complicated.Ryan
11/01/2021, 7:05 AM