Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hydrator is trying to update instead of replace collection entities - can this be prevented? #80

Open
Saeven opened this issue Sep 7, 2023 · 1 comment

Comments

@Saeven
Copy link

Saeven commented Sep 7, 2023

Hello!

In trying to hydrate collection 'changes' (e.g., an update operation) - I've encountered an issue where adding and removing an element from this collection (via Fieldset) in a single operation causes duplicate key problems as Doctrine flushes.

I've created a repository to evidence the difficulties being encountered here:
https://github.com/Saeven/CollectionHydration

Is there a means to achieve what I'm after the "Doctrine way", or is clearing and the repopulating the collection the intended behavior? This collection can contain thousands of entities in production, reissuing so many inserts seems wasteful...

I've got a band-aid for now, but was looking for 'the right way' to get this done!

Thank you.
Alex

@driehle
Copy link
Member

driehle commented Nov 16, 2023

If you look at src/Strategy/AllowRemoveByReference, for instance, you should see that a diff between the two collections is build and the individual elements are indeed added or removed. So, technically, the collection is not rebuilt.

The comparison of objects is based on AbstractCollectionStrategy::compareObjects(), which uses spl_object_hash(). Could it be that your objects in fact are not identical, but different instances of the same entity?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants