Tommy Jeon
09/12/2022, 8:11 PMmodel Foo {
id String @id @default(auto()) @map("_id") @db.ObjectId
title String
bar Bar?
}
model Bar {
id String @id @default(auto()) @map("_id") @db.ObjectId
fooId String @db.ObjectId
foo Foo @relation(fields: [fooId], references: [id], onDelete: Cascade)
}
But when I delete an instance of Bar, the related Foo still remains in the database. Does this referential rule only work in one direction? I.e. only when you delete Foo, the related Bar will delete? How can I make it so deleting a Bar instance cascades to Foo?
I tried adding a @relation(onDelete: Cascade
to the Foo schema, but that triggered a prisma schema error.Tommy Jeon
09/12/2022, 9:04 PMVladi Stevanovic