Prisma1: Disconnecting Many-to-many self relation will delete all relations

Created on 25 Jul 2018  路  2Comments  路  Source: prisma/prisma1

Describe the bug
I'm implementing a following feature using many-to-many self-relation,
let's say X is following Y and Z
when I disconnect X/Y, X/Z got disconnected to

To Reproduce
Steps to reproduce the behavior:

this is my schema

type User {
  id: ID! @unique
  follower: [User!]! @relation(name: "UserFollow")
  following: [User!]! @relation(name: "UserFollow")
}

first connect X/Y and X/Z

mutation {
  updateUser(data:{
    following: {
      connect: [{ id: "Y" }, { id: "Z"}]
    }
  },where:{
    id:"X"
  }) {
    id
  }
}

then disconnect X/Y

mutation {
  updateUser(data:{
    follower: {
      disconnect: [{ id: "X" }]
    }
  },where:{
    id:"Y"
  }) {
    id
  }
}

this is what is got from MySQL log

delete from `test@dev`.`_UserFollow`
  where `test@dev`.`_UserFollow`.`B` = 'X'

so it deletes all relations that X is following

Expected behavior
delete only the relation between X/Y

Versions (please complete the following information):

  • OS: arch linux 4.17.8-1
  • prisma CLI: prisma/1.12.0 (linux-x64) node-v9.11.1
  • Prisma Server: 1.12.0
areengine bu1-repro-available

Most helpful comment

Hey @geniusgordon and @salim-dev ,

thanks for reporting this and the detailed reproductions. I can reproduce it and will fix it right away.

All 2 comments

Post - Category many-to-many

Datamodel
`
type Post {
id: ID! @unique
createdAt: DateTime!
updatedAt: DateTime!
title: String!
content: String!
isPublished: Boolean @default(value: true)
categories: [Category!]!
}

type Category {
id: ID! @unique
createdAt: DateTime!
updatedAt: DateTime!
title: String!
parent: Category @relation(name: "CategoryParent")
children: [Category !]! @relation(name: "CategoryChildrens")
posts: [Post!]!
}
Mutation
mutation {
updatePost(data: { categories: { disconnect: [{ id: "CAT2"}, {id: "CAT5"}, {id: "CAT8"}] }, where {id: "POST1"} })
}
`

exemple
_PostToCategory
before update
| id | A | B
| .... | Post1 | CAT1
| .... | Post1 | CAT2
| .... | Post1 | CAT5
| .... | Post1 | CAT8
| .... | Post2 | CAT4
| .... | Post2 | CAT5
| .... | Post2 | CAT8
after update
| id | A | B
| .... | Post1 | CAT1
| .... | Post2 | CAT4

Versions :

OS: windows 10
prisma CLI: prisma/1.12.0, Mysq/5.7, node-v8.11.1
Prisma Server: 1.12.0
Docker Community Edition: 18.06.0-ce-win72 (19098)

Hey @geniusgordon and @salim-dev ,

thanks for reporting this and the detailed reproductions. I can reproduce it and will fix it right away.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

akoenig picture akoenig  路  3Comments

ragnorc picture ragnorc  路  3Comments

tbrannam picture tbrannam  路  3Comments

dohomi picture dohomi  路  3Comments

thomaswright picture thomaswright  路  3Comments