[DDC-2524] Wrong commit order with cascade remove and double association#707
[DDC-2524] Wrong commit order with cascade remove and double association#707mnapoli wants to merge 1 commit intodoctrine:masterfrom
Conversation
There was a problem hiding this comment.
you don't need this line as it is alreayd the phpunit bootstrap file
|
Code coverage probing that this functionality works was committed as of b070676 |
|
This PR was manually merged into master, but then reverted because it has failing tests (which is the purpose of this PR). As explained in DDC-2524, it is actually a bug fixable in Doctrine, not a limitation of the DB, so could this PR and the Jira ticket be reopened please? |
|
ping Could this PR be reopened? The issue has been reopened, this PR is still useful, it contains a testcase reproducing the bug. |
|
@mnapoli Is this fixed with the DDC-2775 PR? |
|
@beberlei Nope, unfortunately. I just merged this PR with master locally, and it's not fixed (you could also try to re-launch the travis job to confirm this). I re-read both tickets and they are not the same thing. DDC-2775 was an actual bug with cascade order because of lazy collections, DDC-2524 is more about "the cascade order could be improved for this situation to work, because it can be made to work". So it's less of a bug, but more of a improvement on how doctrine chooses the commit order. |
|
I have rebased the pull request and squashed the commits to make it cleaner. That also shows that it's still failing on master. |
|
How do you work around this @mnapoli ? |
|
@Netiul Very badly, sometimes I create a whole function dedicated to deleting the objects: it does the "remove cascade" manually and flushes several times in between (kind of try until it works), sometimes I set the associations as nullable (even though they shouldn't) and have a |
|
@mnapoli That's unfortunate. I was hoping you had a nice work around, since my solution is like yours :) |
|
The best workaround I can come up with is hooking into the PreRemove LifecycleEvent, inside that event remove associations on both sides and call flush again inside the Event. Assuming the remove action is cascaded, the following should work. /** @ORM\HasLifecycleCallbacks */
class Entity
{
/**
* @ORM\PreRemove
*/
public function preRemove(LifecycleEventArgs $lifecycleEvent)
{
//set one-to-one association to null
//for each item in collection of one-to-many association, remove assoc with $this
$em = $lifecycleEvent->getEntityManager();
$em->flush($this);
}
} |
|
👍 thank you! |
|
Good to know. The original code is long gone, but thanks for following up. |
This PR contains the failing test case for DDC-2524.