"set" does not replace relations in update
See original GitHub issueBug description
Following the doc: https://www.prisma.io/docs/reference/api-reference/prisma-client-reference/#set
I could not use the set
query as intended, the request is passing with no error but the relations are not created in database.
How to reproduce
Expected behavior
The items passed to the set
query should update the items in database.
Prisma information
My models:
model Prospecting {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
modifiedAt DateTime @default(now())
transaction String
type String
minPrice Int?
maxPrice Int?
equipped Boolean?
furnished Boolean?
bedrooms Int?
archivedAt DateTime?
cities ProspectingAndCity[] @relation("ProspectingTo_ProspectingAndCity")
}
model ProspectingAndCity {
prospectingId Int
cityId Int
City City @relation("CityTo_ProspectingAndCity", fields: [cityId], references: [id])
Prospecting Prospecting @relation("ProspectingTo_ProspectingAndCity", fields: [prospectingId], references: [id])
@@id([prospectingId, cityId])
@@map("_ProspectingAndCity")
}
model City {
id Int @id @default(autoincrement())
name String
linkedTo String?
ProspectingAndCity ProspectingAndCity[] @relation("CityTo_ProspectingAndCity")
}
The update query:
await prisma.prospecting.update({
where: { id: 2 },
data: {
'transaction': 'L',
'type': 'M',
'minPrice': null,
'maxPrice': null,
'equipped': null,
'furnished': null,
'bedrooms': null,
'archivedAt': null,
'cities': {
'set': [
{
'prospectingId_cityId': {
'prospectingId': 5,
'cityId': 54,
},
},
{
'prospectingId_cityId': {
'prospectingId': 5,
'cityId': 10,
},
},
],
},
},
});
Environment & setup
- OS:
KDE neon User Edition 5.20 x86_64
- Database:
PostgreSQL 12.5 (Debian 12.5-1.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit
- Node.js version:
v15.8.0
- Prisma version:
2.16.0
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Set/Replace many to many relation via connect in Prisma
Hi you guys,. I'm trying to create and update mutation, here is my resolver Mutation: const dailyReport = { createDailyReport: async (parent, args,...
Read more >Create or update one to many relationship in Prisma
I'm providing my solution based on the clarifications you provided in the comments. First I would make the following changes to your Schema....
Read more >Update relationship field item without replacing existing items
Hello,. I have been using this calculation for updating a category field item without replacing the existing selections: [CATEGORY FIELD].
Read more >Relations - typeorm - GitBook
It will default to false , meaning no cascades. Setting cascade: true will enable full cascades. You can also specify options by providing...
Read more >Updating the data - Getting Started - Neo4j
You may already have a node or relationship in the data, but you want to modify ... to find and using the SET...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@richardwardza see my workaround above : https://github.com/prisma/prisma/issues/5456#issuecomment-772994699 Maybe we could ask for a new feature for that, like adding a
replace
instruction. Do you know if that would be possible/easy to implement ? @pantharshit00@jalik Sorry for the late reply here.
Sure go ahead with the feature request. I am going to close this one here.