How to delete relations?


#1

How to delete row with relations other table row? or delete by relational id?
i want delete link with these relations.

mutation

    mutation deleteLinkMutation($linkId:ID!) {
      deleteLink(id:$linkId){
        id
      }
    }

it show me error. realtioned link

schema design:

    type Link implements Node {
      createdAt: DateTime!
      description: String!
      id: ID! @isUnique
      updatedAt: DateTime!
      url: String!
      postedBy: User @relation(name: "UsersLinks")
      votes: [Vote!]! @relation(name: "VotesOnLink")
    }
    type Vote implements Node {
      createdAt: DateTime!
      id: ID! @isUnique
      updatedAt: DateTime!
      user: User! @relation(name: "UsersVotes")
      link: Link! @relation(name: "VotesOnLink")
    }

#2

Thanks for your question! I reformatted your code snippets by surrounding them with triple `, so it’s easier to read :slight_smile:

With the deleteLink mutation, you are not trying to delete the relation, but the node. To only remove the relation (that is, to remove the connection between the Link and Vote nodes), you can use the removeFromVotesOnLink(linkLinkId: ID!, votesVoteId: ID!) mutation instead.

However, at the moment, you will also receive an error message if you run this mutation! The reason is how you setup the link field on the Vote type:

link: Link! @relation(name: "VotesOnLink")

Currently, that’s a required field. By leaving out the exclamation mark:

link: Link @relation(name: "VotesOnLink"),

you can make it optional. Then, both deleteLink and removeFromVotesOnLink will work again :slight_smile:


#3

Does the removeFrom method line still get generated in current Prisma generated client? i’m not seeing it. Was it renamed?