Bug #40389

Orphan Removal in ManyToMany Associations

Added by Christian Müller almost 3 years ago. Updated almost 3 years ago.

Status:Resolved Start date:2012-08-29
Priority:Must have Due date:
Assigned To:Christian Müller % Done:

100%

Category:Persistence
Target version:TYPO3 Flow Base Distribution - 2.0 beta 1
PHP Version: Complexity:easy
Has patch:No Affected Flow version:(any)

Description

The orphanRemoval option in a ManyToMany annotation defaults to FALSE.

In the Flow3AnnotationDriver a check is made for $manyToManyAnnotation->orphanRemoval which in turn will always be FALSE because it is the default (and not only when it was actually set to FALSE in the annotation, which seems to have been the intention of the check). Therefor unless you set it to TRUE anyway it will always go to the elseif which checks if the associated entity has a repository and then sets orphanRemoval to TRUE.

Which means that if you have a ManyToMany relation where one entity has no Repository that will end up with orphanRemoval TRUE regardless of what you really annotated. This is not really the expected behaviour and especially for ManyToMany often wrong too.

I suggest to remove the check for ManyToMany relations and use the actual value that is annotated (or the default FALSE), but that of course is a breaking change as it will leave orphans behind in cases people unknowingly accepted this (wrong) behaviour.


Related issues

related to Doctrine.ORM - Bug #33921: Doctrine's removeElement() deletes OneToMany objects with... Closed 2012-02-14

Associated revisions

Revision ca60d48e
Added by Christian Müller almost 3 years ago

[!!!][BUGFIX] Don't override orphanRemoval setting from Doctrine

In Doctrine 2 ORM, orphanRemoval is disabled by default. In FLOW3 we want
orphanRemoval to happen, if the target is not an aggregate root, changing
the default Doctrine behavior.

Because we want developers to be able to override that override, we had a
check in place, to favor the setting coming from the annotation. But since
there is no way to check if the FALSE in the orphanRemoval of an annotation
is the default or has been explitly set, this would fail to allow an
override with FALSE.

For many-to-many we thus assume that orphanRemoval is very rarely a
useful thing, and thus skip our own default handling.

If you want orphanRemoval on many-to-many associations, you now must
explicitly enable it with the annotation option!

Change-Id: I85c2998f0ce7700d10a8f57b0597eb9d3be4d095
Fixes: #40389
Releases: 1.2

History

#1 Updated by Gerrit Code Review almost 3 years ago

  • Status changed from New to Under Review

Patch set 1 for branch master has been pushed to the review server.
It is available at http://review.typo3.org/14211

#2 Updated by Gerrit Code Review almost 3 years ago

Patch set 2 for branch master has been pushed to the review server.
It is available at http://review.typo3.org/14211

#3 Updated by Karsten Dambekalns almost 3 years ago

  • Assigned To set to Christian Müller
  • Target version set to 2.0 beta 1

#4 Updated by Gerrit Code Review almost 3 years ago

Patch set 3 for branch master has been pushed to the review server.
It is available at http://review.typo3.org/14211

#5 Updated by Christian Müller almost 3 years ago

  • Status changed from Under Review to Resolved
  • % Done changed from 0 to 100

Also available in: Atom PDF