mikro-orm icon indicating copy to clipboard operation
mikro-orm copied to clipboard

onDelete and onUpdateIntegrity in ManyToMany relations

Open belinde opened this issue 3 years ago • 2 comments

Is your feature request related to a problem? Please describe. I have an Attachment entity that can be related to many other entities; if an Attachment is "used" by someone else, it cannot be deleted. ManyToOne relations support the onDelete: 'no action' FK constraint, but ManyToMany no.

Describe the solution you'd like Add the support for onDelete and onUpdateIntegrity in ManyToMany relations

Describe alternatives you've considered Manual check of every relation before deleting an Attachment.

Additional context I'm using MySQL with mikro-orm 4.5 because I have some problem upgrading di version 5 (see https://github.com/mikro-orm/mikro-orm/issues/2130 and I must try again now with the stable version)

belinde avatar Feb 14 '22 08:02 belinde

Add the support for onDelete and onUpdateIntegrity in ManyToOne relations

Here and in the title you say you want to add it to m:1? But that is where it already is, right?

Note that for M:N pivot tables we never do update queries, so there is no reason for onUpdateIntegrity.

B4nan avatar Feb 14 '22 08:02 B4nan

Sorry, my fault, wrong title ant then I copy&pasted.

Regarding onUpdateIntegrity, I'm sure the ORM don't do it, but I think is legit to update a primary key (altough not the best practice, I know). But I agree, it could be avoided. The check on deletions is another thing, IMHO.

belinde avatar Feb 14 '22 08:02 belinde

Closing as this is nowadays possible by defining a pivot entity explicitly.

B4nan avatar Oct 25 '23 22:10 B4nan