英文:
Prisma Relation query with nuxtjs
问题
我是新手,想要在我的应用程序表上连接我的工作表和用户表。谢谢你的帮助。
我的模式如下:
model Job {
id Int @id @default(autoincrement())
society String?
description String?
application Application[]
}
model User {
id Int @id @default(autoincrement())
email String @unique
name String?
applications Application[]
}
model Application {
id Int @id @default(autoincrement())
job Job @relation(fields: [jobId], references: [id])
jobId Int
user User @relation(fields: [userId], references: [id])
userId Int
}
我的代码如下:
const application = await prisma.application.create({
data: {
user: {
connect: { id: 1 },
},
job: {
connect: { id: 1 },
},
},
})
我不知道为什么它不起作用。感谢帮助。
英文:
Hi I'm new to prisma and I want to connect my job and user table on apllication table.
Thx for your help
my schema is :
model Job {
id Int @id @default(autoincrement())
society String?
description String?
application Application[]
}
model User {
id Int @id @default(autoincrement())
email String @unique
name String?
applications Application[]
}
model Application {
id Int @id @default(autoincrement())
job Job @relation(fields: [jobId], references: [id])
jobId Int
user User @relation(fields: [userId], references: [id])
userId Int
}
my code is :
const application = await prisma.application.create({
data: {
users: {
connect: [{ user: {user}, userId: 1 }],
},
jobs: {
connect: [{ jobId: 1 }],
},
},
})
I dont know why its not working.
Thanks for help
答案1
得分: 0
在你的应用程序模型中,没有users
和jobs
,你应该改为使用user
和job
,当你想要连接时,你必须使用唯一值,只需使用id,所以使用以下命令:
const application = await prismaClient.application.create({
data: {
user: {
connect: {
id: 1
}
},
job: {
connect: {
id: 1
}
}
}
})
英文:
In your application model, there are no users
and jobs
, you should use user
and job
instead, when you want to use connect you have to use unique value, id is enough, so use this command:
const application = await prismaClient.application.create(
{
data: {
user: {
connect: {
id: 1
}
},
job: {
connect: {
id: 1
}
}
}
}
)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论