question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

"set" does not replace relations in update

See original GitHub issue

Bug 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:closed
  • Created 3 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
jalikcommented, Mar 26, 2021

@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

await prisma.prospecting.update({
  where: { id: 2 },
  data: {
   ...attributes,
    'cities': {
      // this would remove any links between cities and this prospecting, and create new relations.
      'replace': [
        {
          'prospectingId_cityId': {
            'prospectingId': 5,
            'cityId': 54,
          },
        },
        {
          'prospectingId_cityId': {
            'prospectingId': 5,
            'cityId': 10,
          },
        },
      ],
    },
  },
});
0reactions
pantharshit00commented, May 16, 2021

@jalik Sorry for the late reply here.

Sure go ahead with the feature request. I am going to close this one here.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found