Hello, I want to implement the Cascade Delete but ...
# orm-help
s
Hello, I want to implement the Cascade Delete but I don’t know how to implement it in my case. I have 3 tables which is Document, Media and Post
Copy code
model Media {
    mediaUid            String                  @id      @db.Uuid
    title               String
}

model Document {
    documentUid         String                  @id      @db.Uuid
    title               String
}

model Post {
    postUid             String                  @id      @db.Uuid
    attachedUid         String                           @db.Uuid
    title               String
}
The attachedUid in Post table is the uid of Document or Media. When I delete the Media or Document I want to delete it too in Post.
1
🆘 1
👀 1
r
Hi @See Jee 👋 Please see the documentation on referential actions which will point you in the right direction.
s
@Raphael Etim first thanks for the link. My case which I can’t find online is that the attachedUid could be either Media or Document so I don’t know how to setup that if I delete Media it can find the mediaUid in attacheduid in Post table.
Sir @nikolasburk maybe you can help me
r
From the schema you shared, there isn't any relationship between the models. You will need to first establish some form of relationship between them in order to be able to perform referential actions.
👍 1
s
@Raphael Etim how it will be look like? sorry for asking that.
r
Firstly, what kind of relationship exist between
Media
,
Document
, and
Post
. Is it 1-1, 1-M or M-M? You will need to think in terms of two models say between Media and Document, or Media and Post or Document and Post.
s
it is Post to Document and Media and Document and Media don’t have relationship. I am kinda looking at same approach of polymorphic of laravel.
r
Help me understand clearly, can we say a Post can have many Documents or is it a Document can have many Post?
v
👋 Hello @See Jee, did you end up resolving this problem, or is this something you'd still need help with?
s
Did not solve it.
😥 2
r
Hi @See Jee, You may have missed my last question. I asked if the relationship between Post and Documents is one to one or one to many. With this information, we can safely create a model that establishes relationship between both and then we can perform referential actions such as Cascade delete.
v
👋 Hello @See Jee - did you have a chance to see Raphael's message? Let us know if you still need any help here!