P
Prisma3mo ago
zgy

Nested update when creating single record

Hi Prisma-Community, I want to set two fields to null when I create a user but I have no idea if this is possible.
model Membership {
id String @id @default(cuid())
roles Role[]
user User?
organization Organization @relation(fields: [organizationId], references: [id])
organizationId String
invitedById String?
invitedEmail String? @unique

createdAt DateTime @default(now())
updatedAt DateTime @updatedAt

@@unique([organizationId, invitedEmail])
}
model Membership {
id String @id @default(cuid())
roles Role[]
user User?
organization Organization @relation(fields: [organizationId], references: [id])
organizationId String
invitedById String?
invitedEmail String? @unique

createdAt DateTime @default(now())
updatedAt DateTime @updatedAt

@@unique([organizationId, invitedEmail])
}
I want to set invitedById and invitedEmail to null when I create a user and connect it to the membership. This is the code that works for creating a user and connect the membership relation.
const session = await prisma.session.create({
data: {
expirationDate: getSessionExpirationDate(),
user: {
create: {
email: email.toLowerCase(),
membership: {
connect: {
organizationId,
invitedEmail: email,
},
},
password: {
create: {
hash: hashedPassword,
},
},
},
},
},
select: { id: true, expirationDate: true },
});
const session = await prisma.session.create({
data: {
expirationDate: getSessionExpirationDate(),
user: {
create: {
email: email.toLowerCase(),
membership: {
connect: {
organizationId,
invitedEmail: email,
},
},
password: {
create: {
hash: hashedPassword,
},
},
},
},
},
select: { id: true, expirationDate: true },
});
Is it possible to set the invitedById and invitedEmail to null in the same query?
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server