问题描述
我找不到有关Prisma文档的任何相关信息,也没有关于此问题的信息。
我的相关架构如下:
model User {
id Int @default(autoincrement()) @id
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
firstName String?
lastName String?
email String @unique
hashedPassword String?
role String @default("user")
sessions Session[]
profile Profile?
}
model Profile {
id Int @default(autoincrement()) @id
aboutMe String?
location String?
profession String?
user User @relation(fields:[userId],references: [id])
userId Int
}
我想更新两个表中的多个列,但是无法使该突变在Prisma中工作。因此,这就是我目前的变化:
...
const {aboutMe,location,profession,firstName,lastName } = inputs;
const profile = await db.user.update({
where: { id: ctx.session!.userId },data: {
profile: {
update: {
aboutMe,},});
const user = await db.user.update({
where: { id: ctx.session!.userId },data: {
firstName,lastName,});
...
如您所见,我有两个突变,是否可以用一个突变来更新多个表?
谢谢。
解决方法
这应该有效:
const profile = await db.user.update({
where: { id: u.id },data: {
firstName: 'name',lastName: 'name',profile: {
update: {
aboutMe: 'aboutMe',location: 'aboutMe',profession: 'aboutMe',},include: { profile: true },})