Hey. I have a problem with deleting rows that are ...
# orm-help
k
Hey. I have a problem with deleting rows that are connected through many-to-many. I want to delete all the related fields
onDelete: Cascade
however when I perform a delete operation it only deletes the relation. Here's my models -
model Sale {
id        String            @id @default(uuid())
createdAt DateTime          @default(now())
updatedAt DateTime          @updatedAt
index     Int               @unique @default(autoincrement())
rank      Rank              @default(ROOKIE)
services  ServicesOnSales[]
}
model Service {
id        Int               @id @default(autoincrement())
createdAt DateTime          @default(now())
updatedAt DateTime          @updatedAt
name      String
provision String
sales     ServicesOnSales[]
}
model ServicesOnSales {
saleId       Int
serviceId    Int
createdAt    DateTime @default(now())
updatedAt    DateTime @updatedAt
subscription String
sale         Sale     @relation(fields: [saleId], references: [index], onDelete: Cascade)
service      Service  @relation(fields: [serviceId], references: [id], onDelete: Cascade)
@@id([saleId, serviceId])
}
enum Rank {
ROOKIE
MASTER
VETERAN
}
The query below only deletes the sale and the relation but the service is not getting removed
await prisma.sale.delete({
where: {
id
}
})
2
j
Could you give me full prisma configuration? I mean
Copy code
generator client {
  provider = "prisma-client-js"
}

datasource db {
  provider = "mysql"
  url      = env("DATABASE_URL")
}
which database are you using
v
👋 Hello @Kenny Tran did you have a chance to check Jarupong's questions? Let us know if this is an ongoing problem!
k
Oh sorry, i fixed it on my own. Here, I will mark it for you 😄
🎉 1
v
Awesome, I'm glad to hear it's all resolved! Thank you for letting us know and if you have time, we'd love to know how you ended up resolving this issue - so future users can also use your solution! 😊
prisma rainbow 1
k
Well everything was actually working. The relation from the many-to-many table got deleted along with the sale/service. The problem was that I was trying to find a way to delete both sale & service & the relation which is possible by using the $transaction api, but is not something that should occur intuitively. All and all i read through the documentation and solved the "problem" by trial and error.
🙌 1
💯 1
v
That's ultimately a great learning! Thank you for sharing 💚
1