如何解决在一个查询中更新多个表
我找不到有关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 },})
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。