mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
DDC-2922: Flushing new Entities reachable over several paths that do not all "cascade persist" #3637
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @doctrinebot on GitHub (Jan 17, 2014).
Originally assigned to: @Ocramius on GitHub.
Jira issue originally created by user mpdude:
Please consider the following associations:
A <>--> B <-- CA is an "aggregate" type object w/ a OneToMany collection of Bs. This association is set to cascade persist operations.
C has a unidirectional OneToOne association to B as well.
Adding a new B to A's collection and flushing the EntityManager works - B is persisted (persistence by reachability).
However, when also creating a new C and pointing it to the new B, adding C to the EntityManager and then flushing leads to an exception because B is discovered as a new Entity through a relationship not set to cascade persist operations.
Obviously the problem here is that there are two paths through which we can discover new Entities. The UoW currently starts search from newly (explicitly) added Entities first before it walks through collections of already-managed entities.
I am unsure if it is just a documentation issue or a deeper problem?
If the UoW worked the other way round, the same problem would occur if the cascade persist was on the other association.
A solution would probably require the UoW to first collect all offending (new) Entities and the link they were discovered through, but later on remove Entities from this list if they are found through another association with the cascade persist option. The exception must not be thrown unless the whole reachability graph has been traversed.
@doctrinebot commented on GitHub (Jan 17, 2014):
@doctrinebot commented on GitHub (Aug 18, 2014):
Comment created by @ocramius:
Can this be factored into a failing test case? I'm not sure if we can support it, but the code would make it much easier to track down the issue into something fixable.
@doctrinebot commented on GitHub (Sep 29, 2015):
Comment created by dhager:
I think I just got bitten by this one. My expectation was (is?) that the error should only occur if zero cascade-persist paths are possible in a -transaction- flush.
@doctrinebot commented on GitHub (Sep 29, 2015):
Comment created by dhager:
@ocramius Failing test case created: [https://github.com/doctrine/doctrine2/pull/1521]
@zerocrates commented on GitHub (Feb 26, 2019):
I think this bug was fixed by the merge of #1521?
@Ocramius commented on GitHub (Feb 26, 2019):
Indeed, closing.