Where does the onDelete on relation is applying ?
For instance :
Here the cascade delete will occur when I delete my product entity (and so delete the logistic linked to it)
Or when I delete the logistic (will delete the product linked to it)
10 Replies
In a one-to-many relation, if you use on delete cascade, only by deleting the one, will delete the many. Not the other way
In your case, if you delete a logistics, its corresponding product will be deleted
Thanks for your answer ! So I have to delete manually logistics on product delete ?
I can't answer that question, it's kind of a business logic question. I don't know what is the architecture of your app.
Alright, thanks anyway !
Is this a one to one or a one to many relation?
one to one but my logistics table is used with other tables as well
but as using
.references()
makes the relation mandatory (cannot be null) I cannot put an onDelete on my product table's sideAdding
notNull()
makes the relation mandatory. The references shouldn't make it mandatoryit shouldn't but it does unfortunately
GitHub
[BUG]: A foreign key can not be null · Issue #1264 · drizzle-team/...
What version of drizzle-orm are you using? 0.28.6 What version of drizzle-kit are you using? 0.19.13 Describe the Bug I have schema users table like this export const users = pgTable('users'...
When I try to create an entity without specifying a relation, I get a foreign key constraint error
which is fixed when I remove the
.references()