mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
Wrong FK value update on orphanRemoval & oneToOne when replacing target #5561
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 @akomm on GitHub (May 26, 2017).
Having entity A and B and OneToOne association between them:
A mapping
B mapping:
persisted correctly with A.b = B(id:n)
executed queries:
persisted incorrectly: A.b = null
executed queries:
either 2. is wrong and should update A.b = n+1 or when doctrine is smart to only update values instead of delete & insert, then 3. is wrong and shoult not be executed.
Assignment was done from the owning side with API like this:
@Ocramius commented on GitHub (May 26, 2017):
This needs a test case. As it currently is described, it just looks like
something that worked correctly for ages, yet you found a broken scenario,
and the culprit is unclear.
On 26 May 2017 3:52 p.m., "Andriy Komm" notifications@github.com wrote:
@akomm commented on GitHub (Jun 2, 2017):
I had some problem reproduce it, when I noticed, that my inversed and mapped side is inversed in the test, which made it pass.
So the problem is, when you have a OneToOne and orphanRemoval=true from the inversed side.
https://github.com/akomm/doctrine2/tree/test-for-%236474
I know about the inversed side sync requirement, but in case of one-to-one, even when the
assignNewProofCopychecks for a "current proofCopy" before replacing it and sets its reference to itself to NULL it still does not work. I'm forced to em->remove on the proofCopy. But it is often so, that in your domain you have certain types which are rather managed via others entity API. It is prone, when you have to always know that you have to explicitly em->remove those managed entity, instead of detaching / removing it as being not referenced anymore. This works well in OneToMany, when the One-Side, even though from orm perspective the inversed side, is managin the ManySide, I want to remove via the One-Side and persist the one side and the changes to propagate to the Many side. Works well. But not with OneToOne.@akomm commented on GitHub (Jun 2, 2017):
facepalm
Initially it was not an bi-directional association and so that is the reason I initial had the mapping side on proofCopy. My model required me to make it bi-directional. After changing it I set reivew as inversed and lept proofCopy as mapped. But why the hell not swap them... I'm checking whether it makes any issues in model, if not its resolved I think.
@akomm commented on GitHub (Jun 2, 2017):
Works like a charm.
I think the problem in OneToOne is, that one you switch the reference, the persist is not cascaced to the detached entity, so you have to mark it for removal. And even when you set the reference from the owning side to null in that case, still without explicit persist on it, after detaching the reference on the inverse side and persisting it the persist never reaches the detached entity.
So I think it is not a bug. When a brand new B is persisted (owning side) it is maybe possible to generate a "blind" delete A statement with where A.id = B.a, before inserting the new B. I assume generating probably not required delete statements might be not a desired behavior. But I'm not an expect in this.
If you think the same way this issue can be closed.