mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
Doctrine refresh occurring without refresh added to cascade options #5252
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 @djones8520 on GitHub (Sep 13, 2016).
Doctrine version- 2.5.5-DEV
I'm having a problem with doctrine refresh, refreshing associations even if refresh is not in the cascade options. Below is part of a ymal mapping for an ItemNode entity.
A refresh on an ItemNode object will refresh its data, however, data on its zoneHistory is also being refreshed. For example, ZoneHistory has a status field that was changed earlier, but after the refresh, the status is reverted.
The interesting part, is that any change on the OrderItem is not refreshed unless refresh is added to the cascade.
Thanks for any suggestions.
@fromthecove commented on GitHub (Nov 19, 2018):
I know this is an old issue, but I just ran into something very similar: refresh was cascading to an entity for which I had no cascade refresh configured. After stepping through the code, I discovered when the BasicEntityPersister::refresh method builds its SQL query for the refresh, it takes the FETCH configuration for the associations into account.
By any chance, do you have the fetch mode configured to EAGER anywhere? Perhaps your ItemNode -> zoneHistory fetch? If it is, then when you call refresh on ItemNode, and Doctrine builds the query to reload the data from the database, it will also JOIN in the data for the related zoneHistory because you have it set to eager fetch.
That was my issue. Personally, I think when doing a refresh Doctrine should ignore any configured fetch mode.
@djones8520 commented on GitHub (Dec 4, 2018):
The fetch mode is lazy by default right? If I have it set, it's always lazy. I don't recall ever setting a different fetch mode. I do sort of remember working on something with fetch, but it's been so long that I don't remember what I did. I probably ended up working around it.
@Erdou commented on GitHub (Feb 2, 2021):
Thank you @dlowhorn !
I had a very similar issue: very long or unterminating PHP processes. It was because of
em->refresh()coupled with some cyclicfetch=EAGER. Just reviewed allfetch=EAGERcolumns to remove any cycle (while trying to keep the "best" ones in terms of performance), and I don't have anymore issues.But that said I don't think it would ignore it as
fetch=EAGER's goal is to auto-join for performances, IMHO it should detect cycles to stop at the first encountered one.