Is there a way to set up referential actions to wo...
# orm-help
t
Is there a way to set up referential actions to work in both directions? have two models
Copy code
model 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.
1
https://github.com/prisma/prisma/discussions/15287 Question was answered in a github discussion!
v
That's fantastic, I'm glad to hear your questions has already been answered by Jan! 💯