-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Since v2.19.5 $em->remove($child)
doesn't work if called prior to creating another child and $em->persist($parent)
#11448
Comments
Thanks for the example repo. The main issue is that the Why the Page rows are deleted from database on <=2.19.4 : When Furthermore, the entities are deleted from database only thanks to the fact that The proper fix is to take care of any existing associations before removing the entity: mislavjakopovic/doctrine-orm-issue-11448#1 |
Closing since developers are responsible for maintaining both sides of the association. I think that's stated somewhere in the docs. |
BC Break Report
Summary
Following scenario produces a breaking change after upgrading to
doctrine/orm: "2.19.5"
:OneToMany
relation. Parent relation is configured tocascade: ['persist', 'remove']
$entityManager->remove($child)
$parentRepository->find()
$entityManager->persist($parent)
Persisting a Parent entity directly instead of Child is not the best approach, but afaik there is nowhere written that
it is forbidden. I believe there are some use cases where this can actually be quite practical, instead of having persist child on 10 places in code, a simple persist of parent works here more elegant. It is not the best pattern, but I believe it is a valid behavior, otherwise we wouldn't be even allowed to call persist on already loaded entity manually.
The issue comes from a change where we would remove entity from
identityMap
only upon executing deletion queries (UnitOfWork::executeDeletions
) rather than straight away (UnitOfWork::scheduleForDelete
): #11428Example
Previous Behavior (v2.19.4)
After calling
$entityManager->flush()
Child entity was deleted and a new Child was created and assigned to Parent.Current Behavior (v2.19.5)
After calling
$entityManager->flush()
Child entity is not deleted and a new Child is created and assigned to parent (remove had no effect)How to recreate
Made a test case repository https://github.com/mislavjakopovic/doctrine-orm-issue-11448/ with example code which can be ran quickly via
docker-compose
.Workarounds
In
doctrine/orm: "2.19.5"
for aboveremove()
to have effect we need to either:flush()
call right afterremove()
persist($newPage)
, notpersist(book)
persist(book)
The text was updated successfully, but these errors were encountered: