Yaakov
10/25/2021, 8:33 PMmodel Post {
id Int @id @default(autoincrement())
title String
categories CategoriesOnPosts[]
}
model Category {
id Int @id @default(autoincrement())
name String
posts CategoriesOnPosts[]
}
model CategoriesOnPosts {
post Post @relation(fields: [postId], references: [id])
postId Int // relation scalar field (used in the `@relation` attribute above)
category Category @relation(fields: [categoryId], references: [id])
categoryId Int // relation scalar field (used in the `@relation` attribute above)
assignedAt DateTime @default(now())
assignedBy String
@@id([postId, categoryId])
}
Suppose I want to do the following:
await prisma.post.update({
where: {
title: 'Foo'
},
data: {
categories: {
category: {
name: 'Updated category name'
}
}
}
});
All I get is `"error": "Unknown arg categories
in where.categories for type PostWhereUniqueInput. Did you mean set
?\n"`
Is there any way for this to be accomplished?Ryan
10/26/2021, 5:01 AMYaakov
10/26/2021, 3:51 PMRyan
10/27/2021, 10:40 AMawait prisma.post.update({
where: { id: 1 },
data: {
categories: {
update: {
where: { postId_categoryId: { postId: 1, categoryId: 1 } },
data: { category: { update: { name: 'new name' } } },
},
},
},
})
Yaakov
10/31/2021, 3:56 PM