Skip to content

[DDC-2524] Wrong commit order with cascade remove and double association#707

Closed
mnapoli wants to merge 1 commit intodoctrine:masterfrom
myclabs:CascadeRemoveOrder
Closed

[DDC-2524] Wrong commit order with cascade remove and double association#707
mnapoli wants to merge 1 commit intodoctrine:masterfrom
myclabs:CascadeRemoveOrder

Conversation

@mnapoli
Copy link
Copy Markdown
Contributor

@mnapoli mnapoli commented Jun 24, 2013

This PR contains the failing test case for DDC-2524.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you don't need this line as it is alreayd the phpunit bootstrap file

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed thanks

@guilhermeblanco
Copy link
Copy Markdown
Member

Code coverage probing that this functionality works was committed as of b070676

@mnapoli
Copy link
Copy Markdown
Contributor Author

mnapoli commented Aug 9, 2013

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?

@mnapoli
Copy link
Copy Markdown
Contributor Author

mnapoli commented Nov 4, 2013

ping

Could this PR be reopened? The issue has been reopened, this PR is still useful, it contains a testcase reproducing the bug.

@Ocramius Ocramius reopened this Nov 4, 2013
@beberlei
Copy link
Copy Markdown
Member

beberlei commented Jan 3, 2014

@mnapoli Is this fixed with the DDC-2775 PR?

@mnapoli
Copy link
Copy Markdown
Contributor Author

mnapoli commented Jan 3, 2014

@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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Fixed

@mnapoli
Copy link
Copy Markdown
Contributor Author

mnapoli commented Apr 29, 2014

I have rebased the pull request and squashed the commits to make it cleaner. That also shows that it's still failing on master.

@zluiten
Copy link
Copy Markdown
Contributor

zluiten commented Apr 29, 2014

How do you work around this @mnapoli ?

@mnapoli
Copy link
Copy Markdown
Contributor Author

mnapoli commented Apr 29, 2014

@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 onDelete: SET NULL or something like that (I don't remember exactly I'm not working on that code right now).

@zluiten
Copy link
Copy Markdown
Contributor

zluiten commented Apr 29, 2014

@mnapoli That's unfortunate. I was hoping you had a nice work around, since my solution is like yours :)

@zluiten
Copy link
Copy Markdown
Contributor

zluiten commented Apr 29, 2014

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);
    }
}

@Ocramius Ocramius changed the title [#DDC-2524] Wrong commit order with cascade remove and double association [DDC-2524] [Test] Wrong commit order with cascade remove and double association Jan 13, 2015
@Ocramius Ocramius changed the title [DDC-2524] [Test] Wrong commit order with cascade remove and double association [DDC-2524] Wrong commit order with cascade remove and double association Jan 24, 2015
@guilhermeblanco
Copy link
Copy Markdown
Member

@mnapoli I'm taking over this PR through a new one, managed by Doctrine itself #1570 including not only your test case, but also another one reported in the ticket (which looks like it was already fixed by my orphanRemoval support on CollectionPersister committed earlier this year.

@mnapoli
Copy link
Copy Markdown
Contributor Author

mnapoli commented Nov 25, 2015

👍 thank you!

@guilhermeblanco
Copy link
Copy Markdown
Member

@mnapoli on your second test testMany, you actually have a mapping issue.
You have to define the onDelete="SET NULL" because there's no way to control inverse awareness.

Once you change that, you fall back to same error as testSingle, which I addressed on #1570

@mnapoli
Copy link
Copy Markdown
Contributor Author

mnapoli commented Nov 27, 2015

Good to know. The original code is long gone, but thanks for following up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants