Cannot use "set" when joining entities in an explicit ManyToMany table
See original GitHub issueBug description
It appears that when creating an explicit many-to-many join table in Prisma, I cannot use the keyword set
when joining related entities during an update
. I receive the following error:
The change you are trying to make would violate the required relation ‘ArtistReleaseToRelease’ between the
ArtistRelease
andRelease
models."
Given the following schema.prisma
, I have an Artist
a Release
and an ArtistRelease
join table. This was necessary because I needed to associate a verified
property on the join table:
model Release {
id Int @id @default(autoincrement())
title String
artists ArtistRelease[]
}
model Artist {
id Int @id @default(autoincrement())
name String
releases ArtistRelease[]
}
model ArtistRelease {
artist Artist @relation(fields: [artistId], references: [id])
artistId Int
release Release @relation(fields: [releaseId], references: [id])
releaseId Int
verified Boolean @default(false)
@@id([artistId, releaseId])
}
However, when I try and use the update
method and set
the artists
(since all of them might change or be replaced), I run the following command and receive the error above:
const response = await ctx.db.release.update({
where: {
id: 1
},
data: {
artists: {
set: {
artistId_releaseId: {
artistId: 1,
releaseId: 1
}
}
}
}
})
I attempted to use set
on an implicit join table I have in my project and it worked as expected. My only idea is that I need to make both the release
and artist
nullable in ArtistRelease
and then create a id
primary key for that instead of using a composite primary key but going off the docs, I didn’t see an explicit join table defined this way so I wasn’t sure. Any insight here would be appreciated!
Expected behavior
I expect to be able to use the set
method when using an explicit many-to-many join table in Prisma.
Environment & setup
- OS: MacOS
- Database: PostgresSQL
- Node.js version: v12.16.2
- Prisma version:
@prisma/cli : 2.9.0
@prisma/client : 2.9.0
Current platform : darwin
Query Engine : query-engine 369b3694b7edb869fad14827a33ad3f3f49bbc20 (at node_modules/@prisma/cli/query-engine-darwin)
Migration Engine : migration-engine-cli 369b3694b7edb869fad14827a33ad3f3f49bbc20 (at node_modules/@prisma/cli/migration-engine-darwin)
Introspection Engine : introspection-core 369b3694b7edb869fad14827a33ad3f3f49bbc20 (at node_modules/@prisma/cli/introspection-engine-darwin)
Format Binary : prisma-fmt 369b3694b7edb869fad14827a33ad3f3f49bbc20 (at node_modules/@prisma/cli/prisma-fmt-darwin)
Studio : 0.296.0
EDIT: After more digging, does this have to do with cascade deletes not working yet? https://github.com/prisma/prisma/issues/2328
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:9 (5 by maintainers)
Top GitHub Comments
Workaround: upsert & deleteMany
I can reproduce using on
4.3.1
(and with our internal dev version4.4.0-dev.30
) with the repo https://github.com/PeerasakRattanamanee/4032