mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
Changes to one-to-one relations get reversed when the inverse side is fetched again using findBy #5652
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 @johanderuijter on GitHub (Aug 21, 2017).
Originally assigned to: @johanderuijter on GitHub.
I found some unexpected behaviour with one to one relations. I couldn't find any information on it, so i hope it's ok i opened an issue about it here.
My problem is the following:
I have 2 entities, with a bidirectional one to one relation. When i remove the relation between them (e.g. set the properties to null) the relation is removed. However, when the inverse side is fetched again (after setting the relation to null, but before a flush) the relation reappears. This is not the case for 'regular' properties which remain changed.
In my particular use case, this is a problem as the symfony unique constraint uses the repositories findBy to check if an entity already exists. In doing so, it restores the relation.
Here is a code example based on the bidirectional one to one mapping from the docs:
Given the following two entities:
with the following schema:
And the following code:
tested on latest stable (doctrine/orm v2.5.10)
As I could not find much information on this, I don't know if this is a bug, know limitation or even intended behaviour?
If more information is needed, please let me know.
@Ocramius commented on GitHub (Aug 25, 2017):
@johanderuijter does the same thing happen when using DQL? Also, can you try removing the cascade operation and seeing if this affects the issue?
@Ocramius commented on GitHub (Aug 25, 2017):
@johanderuijter one thing that would help a lot is reporting this as a PR containing a failing test. See
61404e2d6d/tests/Doctrine/Tests/ORM/Functional/Ticketfor examples.@johanderuijter commented on GitHub (Aug 25, 2017):
I'll try to create a PR with failing tests later today. Are there any naming conventions i should be aware of? The examples seem to be all over the place with regards to that.
@Ocramius commented on GitHub (Aug 25, 2017):
@johanderuijter I wouldn't worry about it - can be adapted when at review stage.
@johanderuijter commented on GitHub (Aug 25, 2017):
Created a PR with the failing test case.
Using either
findor a DQL query work as expected (e.g. the relations remains null after). The cascade operation also seems to have no effect on this.The relation only reappears when
findByorfindOneByis used and the entity is part of the result.