symfony/symfony — Issue #3539: [Form] collection type is broken
Author: mvrhov
Created: 2012-03-09 11:16:43+00:00
State: open

This one is a bit hard to explain, but I'll try my best.

PR#3239 brought proper handling of collections, but it doesn't work as expected.
My collection object is having duplicates. And those duplicates show to the same memory address
(debugger shows the same for object pairs)
This shows, that the data is bind to the collection twice first in the form's bind() and then
once again in MergeCollectionListener.

When onBindNormData is called $originalData
https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Form/Extension/Core/EventListener/MergeCollectionListener.php#L142
already contains the whole collection that came in through the request.

Later down the code calls add* method and reads the same objects.
Now the problem is not visible if all you do with the data is just call $em->persist($form->getData()
as doctrine will silently handle this, but if you need to traverse the collection and do some calculations
on it before persisting, then you have the problem as you'll do the whatever you want to do twice.