我正在使用 planetscale,我有一个连接到提交调查的用户的调查模型。
我的架构如下
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "mysql"
url = env("DATABASE_URL")
relationMode = "prisma"
}
model Survey {
id String @id @default(cuid())
title String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
authorId String
author User @relation(fields: [authorId], references: [id])
answers Answer[]
@@index([authorId])
}
model User {
id String @id @default(cuid())
name String?
email String? @unique
emailVerified DateTime?
image String?
password String? @default(cuid())
role String @default("USER")
surveys Survey[]
}
这就是我调用创建调查的地方
const author = await db.user.findUnique({
where: { email: user.email as string },
});
if (!author) {
return res.status(401).json({ error: "Not authenticated" });
}
console.log("author", author);
const survey = await db.survey.create({
data: {
answers: {
createMany: {
data: parsedAnswers as any,
},
},
title: req.body.title,
author: {
connect: {
id: author.id,
}
},
},
include: {
author: true,
},
});
当我只使用 connect 时,它会给我这个错误
Error:
Invalid `prisma.survey.create()` invocation:
...
author: {
connect: {
id: "****"
}
},
+ authorId: String
},
include: {
author: true
}
}
Argument `authorId` is missing.
at handleSubmit (webpack-internal:///(app-client)/./app/assessment2/Form.tsx:74:23)
当我尝试添加 id
title: 'B',
author: {
connect: {
id: '***'
}
},
authorId: '***'
~~~~~~~~
},
include: {
author: true
}
}
Unknown arg `authorId` in data.authorId for type SurveyCreateInput. Did you mean `author`? Available args:
type SurveyCreateInput {
id?: String
title: String
createdAt?: DateTime
updatedAt?: DateTime
author: UserCreateNestedOneWithoutSurveysInput
answers?: AnswerCreateNestedManyWithoutSurveyInput
reviewedBy?: UserCreateNestedOneWithoutReviewsInput
}
我正在使用下一个 js 应用程序目录,我想将调查连接到用户