flush([$one]) does not flush changes of the $manies (cascade all is set) #6275

Closed
opened 2026-01-22 15:30:00 +01:00 by admin · 5 comments
Owner

Originally created by @dominikzogg on GitHub (Aug 2, 2019).

Bug Report

Q A
BC Break no
Version 2.6.3

Summary

We tried to flush the one side and expected that the changes on the manies side are flushed to.

Current behavior

The changes of the manies gets ignored, when the manies already exist in the database.

https://github.com/doctrine/orm/blob/2.6/lib/Doctrine/ORM/UnitOfWork.php#L912

How to reproduce

Create a bidirectional one to many relation. Set cascade to all and add orphanRemoval.

<?php 

foreach ($one->getManies() as $many) {
    $many->setValue('value');
    $entityManager->persist($many);
}

$entityManager->flush([$one]);

Changes on $one will be flushed, add and remove on manies will be flushed, but not changes.

Expected behavior

Changes on $one will be flushed, add and remove on manies will be flushed, changes on manies will be flushed.

Originally created by @dominikzogg on GitHub (Aug 2, 2019). ### Bug Report <!-- Fill in the relevant information below to help triage your issue. --> | Q | A |------------ | ------ | BC Break | no | Version | 2.6.3 #### Summary We tried to flush the one side and expected that the changes on the manies side are flushed to. #### Current behavior The changes of the manies gets ignored, when the manies already exist in the database. https://github.com/doctrine/orm/blob/2.6/lib/Doctrine/ORM/UnitOfWork.php#L912 #### How to reproduce Create a bidirectional one to many relation. Set cascade to all and add orphanRemoval. ```php <?php foreach ($one->getManies() as $many) { $many->setValue('value'); $entityManager->persist($many); } $entityManager->flush([$one]); ``` Changes on $one will be flushed, add and remove on manies will be flushed, but not changes. #### Expected behavior Changes on $one will be flushed, add and remove on manies will be flushed, changes on manies will be flushed.
admin added the BugMissing Tests labels 2026-01-22 15:30:00 +01:00
admin closed this issue 2026-01-22 15:30:00 +01:00
Author
Owner

@lcobucci commented on GitHub (Aug 2, 2019):

Flushing specific entities has known issues and is kind of a big pain, hence the removal from v3.

Sorry to frustrate you with this answer but our recommendation is to not rely on that 😕

@lcobucci commented on GitHub (Aug 2, 2019): Flushing specific entities has known issues and is kind of a big pain, hence the removal from v3. Sorry to frustrate you with this answer but our recommendation is to not rely on that 😕
Author
Owner

@dominikzogg commented on GitHub (Aug 2, 2019):

@lcobucci thanks for you fast response. The answer is OK for me.

What we tried:

  1. flush($one)
  2. flush throws DeadlockException
  3. recreate entity manager with a event manager containing only postFlush events (did not worked anyway, cause event manager needs to be same as on connection, which we don't like to change)
  4. ask the old unity of work if its a insert, update or delete, and to persist and remove
  5. flush again

So you give me another good reason to stop trying todo dirty hacks.

@dominikzogg commented on GitHub (Aug 2, 2019): @lcobucci thanks for you fast response. The answer is OK for me. What we tried: 1. flush($one) 2. flush throws DeadlockException 3. recreate entity manager with a event manager containing only postFlush events (did not worked anyway, cause event manager needs to be same as on connection, which we don't like to change) 4. ask the old unity of work if its a insert, update or delete, and to persist and remove 5. flush again So you give me another good reason to stop trying todo dirty hacks.
Author
Owner

@SenseException commented on GitHub (Aug 14, 2019):

Being able to flush specific entities like flush($one) won't be able starting with 3.0. You would depend on a different solution if an update to 3.0 happens.

https://github.com/doctrine/orm/blob/master/UPGRADE.md#bc-break-removed-entitymanagerflushentity-and-entitymanagerflushentities

@SenseException commented on GitHub (Aug 14, 2019): Being able to flush specific entities like `flush($one)` won't be able starting with 3.0. You would depend on a different solution if an update to 3.0 happens. https://github.com/doctrine/orm/blob/master/UPGRADE.md#bc-break-removed-entitymanagerflushentity-and-entitymanagerflushentities
Author
Owner

@lcobucci commented on GitHub (Oct 1, 2019):

@dominikzogg just flush() should, in theory, work. Based on your snippet I can't really find a reason why it doesn't. Would you be willing to shoot us a PR with a failing functional test case?

@lcobucci commented on GitHub (Oct 1, 2019): @dominikzogg just `flush()` should, in theory, work. Based on your snippet I can't really find a reason why it doesn't. Would you be willing to shoot us a PR with a failing functional test case?
Author
Owner

@dominikzogg commented on GitHub (Oct 2, 2019):

@lcobucci we're stopped trying to create this hack as mentioned in comment https://github.com/doctrine/orm/issues/7788#issuecomment-517831855 . I suggest to close the issue.

@dominikzogg commented on GitHub (Oct 2, 2019): @lcobucci we're stopped trying to create this hack as mentioned in comment https://github.com/doctrine/orm/issues/7788#issuecomment-517831855 . I suggest to close the issue.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#6275