Demian N
04/18/2022, 3:49 AMconnect
or not when creating a row with a foreign key field?
I note the result is the same but what would I choose one over the another one? Or this just for a declarative/semantical reason?
Example:
model User {
id String @id @default(cuid())
name String?
email String? @unique
emailVerified DateTime?
image String?
accounts Account[]
sessions Session[]
rooms Room[]
}
model Room {
id Int @id @default(autoincrement())
userId String
title String
description String @db.Text
user User @relation(fields: [userId], references: [id])
@@unique([userId, title])
}
From the above schema, If I would like to add a new room I could do:
Let's say user
hs already being resolved to a user found in the User model
prisma.room.create({ data: { title, description, user: { connect: { id: user!.id } } }})
or also,
prisma.room.create({ data: { title, description, userId: user!.id }} )
What is the correct way?Nurul
04/20/2022, 11:02 AM