title: Zend Framework child collection not hydrating properly
body: <p>I have an issue with the values of a child collection not being hydrated properly. I'm using zend framework 3 with doctrine 2.</p>
  
  <p>Since it's a lot of code that I would have to copy, I will describe what I'm doing and if needed I will update with code.</p>
  
  <p>We have the following:</p>
  
  <ul>
  <li>VillaForm which is a Form element</li>
  <li>VillaFieldset which is a Fieldset element and is the base fieldset of VillaForm</li>
  <li><p>FacilityCategoriesFieldset which is a Fieldset that is used for a Collection element in the VillaFieldset</p>
  
  <pre><code>    $this-&gt;add([
      'type' =&gt; 'Zend\Form\Element\Collection',
      'name' =&gt; 'facilityCategories',
      'options' =&gt; [
          'count' =&gt; 1,
          'allow_add' =&gt; true,
          'allow_remove' =&gt; true,
          'create_new_objects' =&gt; true,
          'target_element' =&gt; [
              'type' =&gt; FacilityCategoryFieldset::class,
          ],
      ],
  ]);
  </code></pre></li>
  <li><p>FacilitiesFieldset which is a a Fieldset that is used for a Collection element in the FacilityCategoriesFieldset</p>
  
  <pre><code>    $this-&gt;add([
      'type' =&gt; 'Zend\Form\Element\Collection',
      'name' =&gt; 'facilities',
      'options' =&gt; [
          'count' =&gt; 1,
          'allow_add' =&gt; true,
          'allow_remove' =&gt; true,
          'create_new_objects' =&gt; true,
          'target_element' =&gt; [
              'type' =&gt; FacilityFieldset::class,
          ],
      ],
  ]);
  </code></pre></li>
  </ul>
  
  <p>So viewing from above we have</p>
  
  <p><code>VillaForm contains VillaFieldset that contains Collection of FacilityCategoriesFieldset which contains a Collection of FacilitiesFieldset</code></p>
  
  <p>Let's say we have this example on the actual form page.</p>
  
  <pre><code>- Row A of FacilityCategoriesFieldset 
    - Row 1 of FacilitiesFieldset
    - Row 2 of FacilitiesFieldset
    - Row 3 of FacilitiesFieldset
  
  - Row B of FacilityCategoriesFieldset 
    - Row x of FacilitiesFieldset
    - Row y of FacilitiesFieldset
    - Row z of FacilitiesFieldset
  </code></pre>
  
  <p>My issue is that after the form is submitted, although the post data is correct, after the hydration the result will  be like so:</p>
  
  <pre><code>- Row A of FacilityCategoriesFieldset 
    - Row x of FacilitiesFieldset
    - Row y of FacilitiesFieldset
    - Row z of FacilitiesFieldset
  
  - Row B of FacilityCategoriesFieldset 
    - Row x of FacilitiesFieldset
    - Row y of FacilitiesFieldset
    - Row z of FacilitiesFieldset
  </code></pre>
  
  <p>The rows of the FacilitiesFieldset of the very last row of the FacilityCategoriesFieldset are used for all the rows of FacilitiesFieldset.</p>
  
  <p>This only happens when a have a fieldset with a collection with another collection. Does anyone have a hint of what I might be doing wrong?
  I will give you any other info/code if you need it.</p>
  
  <p>Thanks a lot.</p>