mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
One-To-Many Bidirectional: Does not updates inverseSide cached collection. #5882
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 @max-zu on GitHub (Feb 14, 2018).
Originally assigned to: @max-zu on GitHub.
I have two Entities Company and Storage with One-To-Many Bidirectional relationship. Entities and their relations are cached (doctrine second level cache). The issue is that, when i create a new Storage entity, Company storages collection doesn't have this new entity until I clear the cache manually.
I tried Doctrine 2.5./2.6./2.6.@dev
PHP 7.2/Postgres9.6/
@Ocramius commented on GitHub (Feb 14, 2018):
Requires a test case to reproduce the issue with a minimal scenario
@max-zu commented on GitHub (Feb 15, 2018):
186c6170e1I used entities from Doctrine tests. Am i wrong, that when i create owning side Entity, i also need call addMethod() on inverse side ? Should the collection be updated automatically if I use cascade
operations ?
@lcobucci commented on GitHub (Feb 20, 2018):
@max-zu you're always responsible for setting both sides of the association.
@max-zu commented on GitHub (Feb 20, 2018):
@lcobucci So what about Cascade Operations ??? If I have cascading links on the OwnerSide, why InverseSide collection is not updated?
@lcobucci commented on GitHub (Feb 22, 2018):
@max-zu can you send the functional test as suggested by @Ocramius (it's way easier to understand what you're trying to achieve with that)?
@nesk commented on GitHub (Jun 24, 2019):
@Ocramius Since the author didn't provided one, here's a test case to help you reproduce the bug: https://github.com/nesk/doctrine-cascade-refresh-showcase
The last command should output this:
The project has two entities, a
Userentity owns multipleProjectentities. Both of them have thecascade={"refresh"}option on their relationship.The
run_showcase.phpfile creates one instance of each entity, links them and persists them.We have two tests, the first one refreshes the inverse side (the
Userentity), the second one refreshes the owning side (theProjectentity).Each test edits the name of the two entities, outputs them, then refreshes one of the two entities and then outputs the names once again (both should have been replaced by the ones in the database).
You can see in the first test, the
Projectentity hasn't been refreshed, while in the second test, both of the entities have been properly refreshed.@nesk commented on GitHub (Mar 26, 2020):
Any news about this issue? I've provided a reproducible test case months, is there anything more I can do to help resolve this bug?
@nesk commented on GitHub (Mar 26, 2020):
So, I've been tweaking a bit the code, and the issue seems to be here:
8c259ea5cb/lib/Doctrine/ORM/UnitOfWork.php (L1825-L1828)When the collection is unwrapped, it returns an empty array, because the
PersistentCollectionhasn't loaded the items.Adding
\iterator_to_array($relatedEntities);before the line1827solves the issue and the entities in the collection are properly refreshed. However, this doesn't seem to be the answer to the problem. The real issue is when you create and persist an entity which contains a filledArrayCollection, once the entity is persisted, the filledArrayCollectionis replaced by an emptyPersistentCollection.Also, I'm not sure how all of this handles deleted entities in the collection?