This post is the top search result for both implicit and explicit disconnect many to many. If you want to completely disconnect an implicit many to many:

const data = await prisma.group.update({
    where: {
        id: groupId,
    },
    data: {
        users: {
            set: [],
        },
    },
});

Gotten from here: https://github.com/prisma/prisma/issues/5946

🌐
Reddit
reddit.com › r/node › can i toggle relation connect and disconnect in prisma orm?
r/node on Reddit: Can I toggle relation connect and disconnect in Prisma ORM?
April 5, 2022 -

I want to implement a LIKE POST feature in my app using express and Prisma ORM. Is it possible to chain the connect and disconnect for the table relation.

This is my current code, but it can only connect the relation.

But what I want to do is, if the current user (req.user.id) hits the same endpoint, then disconnect the relation.

  const likedPost = await prisma.like.update({
    where: {
      postId: req.params.postId,
    },
    data: {
      liker: { connect: { userId: req.user.id } },
    },
    include: {
      post: true,
    },
  });

Any kind of help is highly appreciated. Thanks

Discussions

Pass falsy values to disconnect a relation
When there's an optional 1:1 relation ... to cleanly "update if exists or disconnect if the new value is falsy" on relations. this occurs a lot in the "edit" handler of a resource, which would handle a form submit for example. Right now, prisma-client-js doesn't accept null as a ... More on github.com
🌐 github.com
9
May 6, 2020
explicit m:n relationships incorrect handling of disconnect
In explicit m:n relationships, a disconnect should internally run a delete rather than attempting to set the value to null. See reproduction case. ... prisma : 4.3.1 @prisma/client : 4.3.1 Current platform : darwin Query Engine (Node-API) : libquery-engine c875e43600dfe042452e0b868f7a48b817b9640b ... More on github.com
🌐 github.com
4
1
October 7, 2022
How can I disconnect a relation by using it's fields?
I need to disconnect a relation, but I cannot access the actual relation field due to the way it is setup. Let's say there is a relation called `author`, and I only have access to `authorId`, can I disconnect it by setting `authorId` to null/undefined? More on answeroverflow.com
🌐 answeroverflow.com
August 30, 2024
Overide entire relation field with Prisma? - Stack Overflow
With Prisma is it possible to completely overwrite a relation rather than connecting and disconnecting individual nodes? Say I have a user with a groups relation to groups 1 and 2: user: { ... More on stackoverflow.com
🌐 stackoverflow.com
🌐
GitHub
github.com › prisma › prisma › discussions › 19337
How to disconnect model in many to many relation on delete · prisma/prisma · Discussion #19337
const [, tag] = await prisma.$transaction([ prisma.tag.update({ where: { id, }, data: { materials: { disconnect: tagMaterials.map((material) => ({ id: material.id, })), }, }, }), prisma.tag.delete({ where: { id, }, }), ]);
Author   prisma
🌐
GitHub
github.com › prisma › prisma › issues › 5044
Pass falsy values to disconnect a relation · Issue #5044 · prisma/prisma
May 6, 2020 - Because prisma will throw when ... __ models are not connected.), we have to fetch the current resource, see if it has the relation, and then conditionally execute a disconnect, which is super brittle....
Author   prisma
🌐
Answer Overflow
answeroverflow.com › m › 1279216080627171430
How can I disconnect a relation by using it's fields? - Prisma
August 30, 2024 - Hi @Asleep 👋 To disconnect the author relation, you can set the authorId to null in your update query: await prisma.post.update({ where: { id: 1 }, data: { authorId: null, }, }); await prisma.post.update({ where: { id: 1 }, data: { authorId: ...
Find elsewhere
🌐
GitHub
github.com › prisma › prisma › discussions › 16714
Why there is no disconnect option for one-to-many relation? · prisma/prisma · Discussion #16714
I don't know how to "upsert" a relation record, so I'm trying to disconnect all relations before I "re-relate" It's okay while I'm trying to do so with Tags,Columns, but I can't do that with Category, I don't know why. ... if (artid) { // update await this.prisma.article.update({ where: { artid: artid, }, data: { column: { disconnect: true, // disconnect one record (https://www.prisma.io/docs/concepts/components/prisma-client/relation-queries#disconnect-a-related-record) }, category: { disconnect: true, // >>>>>>✋✋✋✋LOOK HERE✋✋✋✋<<<<<< // ERROR HINT: "error TS2322: Type '{ disconnect: true; }' is not assignable to type 'CategoryUpdateOneRequiredWithoutArticlesNestedInput'.
Author   prisma
🌐
GitHub
github.com › prisma › prisma › discussions › 6037
disconnect relation if exists · prisma/prisma · Discussion #6037
how to disconnect relation if exists whithout getting this error: The records for relation ProfileToUser between the User and Profile models are not connected. const user = await prisma.user.update({ where: { email: 'bob @prisma.io' }, data: { profile: { disconnect: true, }, }, })
Author   prisma
🌐
Prisma
prisma.io › home › connection management › connection management › connection management › connection management › connection management
Connection management | Prisma Documentation
In most cases, you do not need to explicitly call these methods. PrismaClient automatically connects when you run your first query, creates a connection pool, and disconnects when the Node.js process ends.
🌐
GitHub
github.com › prisma › prisma › discussions › 23372
Clarification on `connect`/`disconnect` · prisma/prisma · Discussion #23372
However, Prisma provides a more explicit way to disconnect a relation using the disconnect keyword. Remember that if you want to set a relation to null, you should use disconnect instead of setting the foreign key to null directly.
Author   prisma
🌐
GitHub
github.com › prisma › prisma › issues › 5946
Disconnect with implicit many-to-many does not work · Issue #5946 · prisma/prisma
March 2, 2021 - Models with implicit many-to-many ... to disconnect those relations. model Post { id Int @id @default(autoincrement()) authors Author[] @relation("AuthorToPost") } model Author { id Int @id @default(autoincrement()) posts Post[] @relation("...
Author   prisma
🌐
Reddit
reddit.com › r/node › problem to connect / disconnect records with prisma
r/node on Reddit: Problem to connect / disconnect records with Prisma
October 11, 2023 -

I have a Prisma request in which I'm getting an array of tags (a tag is just a string) that I have to use in an update request.

Here's the request:

      await prisma.node.update({ 
         where: { id, tenantId: tenantId as string }, 
         data: { 
           question: { 
             update: { 
               where: { id: questionId as string }, 
               data: { 
                 text: text as string, 
                 slug: slug as string, 
                 user: { connect: { id: userId } }, 
               }, 
             }, 
           }, 
           tags: { 
             updateMany: tags.map((tag: string) => { 
               return { 
                 where: { id: tag, tenantId }, 
                 data: { id: tag, tenantId }, 
               }; 
             }), 
           }, 
         }, 
       });

The problem is that I can only add tags but not remove them so if I have one tag I can add another one fine but after that I can't remove it.
I tried to use updateOrCreate but it was not working.
What should I use to make the removal of a tag work ?

🌐
Linen
linen.dev › s › prisma › t › 2360807 › is-there-a-way-to-disconnect-relations-using-prisma-upsert-f
Is there a way to disconnect relations using `prisma upsert` Prisma #orm-help
EventOptions other relations intact. Is there a way to replace the connections with only the ... disconnect? https://www.prisma.io/docs/concepts/components/prisma-client/relation-queries#update-an-existing-user-record-by-disconnecting-the-profile-record-its-connected-to
🌐
GitHub
github.com › prisma › prisma › issues › 5005
[BREAKING CHANGE] Disconnect/connect (for relations) throws errors needlessly · Issue #5005 · prisma/prisma
September 11, 2019 - Problem Currently when you try to connect or disconnect relationships, you need to be needlessly cautious that you haven't done it before, otherwise the command will throw. It's weird that it throws, seeing as the state of the data after...
Author   prisma
🌐
GitHub
github.com › prisma › prisma › issues › 4194
Allow relation disconnect without knowing current state of relation · Issue #4194 · prisma/prisma
November 9, 2020 - Problem The use of disconnect will throw an error if no relation is present. However, there are many cases where the user may not know whether or not a relation exists while wanting to ensure it that, whatever the current state, a relati...
Author   prisma