How to remove orphaned relations or manage relationship synchronisation? #543
Unanswered
krishna-404
asked this question in
Q&A
Replies: 2 comments
-
|
For one-to-many/one-to-one you can use For many-to-many, as far as I know this is not implemented and you should delete them manually. For example It's better to wrap it in a transaction. db.transaction(async () => {
await db.product.find(id).chain('medias').delete()
await db.product.find(id).delete()
})It's worth adding cascade deletes option in relations config to automate this. |
Beta Was this translation helpful? Give feedback.
0 replies
-
|
This is if the product is itself to be deleted right?
I don’t want to do that. I want the joint table (product-media) to be
deleted & not the product itself.
…On Mon, 28 Jul 2025 at 1:34 AM, Roman Kushyn ***@***.***> wrote:
For one-to-many/one-to-one you can use onDelete: 'CASCADE' option in the
foreign key, then Postgres will take care of deleting orphaned records.
For many-to-many, as far as I know this is not implemented and you should
delete them manually. For example
<https://orchid-orm.netlify.app/guide/relation-queries.html#delete>
It's better to wrap it in a transaction.
db.transaction(async () => {
await db.product.find(id).chain('medias').delete()
await db.product.find(id).delete()})
—
Reply to this email directly, view it on GitHub
<#543 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/APAJCB3MY6QXJPJZKKVBRYT3KUWDTAVCNFSM6AAAAACCIB3BQWVHI2DSMVQWIX3LMV43URDJONRXK43TNFXW4Q3PNVWWK3TUHMYTGOJQGM2DOMI>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
How to remove orphaned relations or manage relationship synchronisation?
For both one-to-many & many-to-many relationships?
For example a product was created with links to 5 medias. During edit/update one of the medias was delinked. How to delete the removed media?
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions