<p dir="auto">Hi all, it's a bit difficult to explain the problem I'm facing but I'll try:</p>
<p dir="auto">I have a Form with lot of fields, some of them can be dynamically added\removed. When the added field correspond to an entity whose FormType has not any other collection of embedded forms, it works fine both the rendering of the template and the submit with the save on the DB (with Doctrine2.1.7). When the added entity has at least a collection of fields, I get the following error:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Catchable Fatal Error: Argument 1 passed to AIC\UserBundle\Entity\AnagraficaPersone::setRubriche() must be an instance of Doctrine\Common\Collections\ArrayCollection, array given, called in /Applications/MAMP/htdocs/AIC_22-5-12/vendor/symfony/src/Symfony/Component/Form/Util/PropertyPath.php on line 347 and defined in /Applications/MAMP/htdocs/AIC_22-5-12/src/AIC/UserBundle/Entity/AnagraficaPersone.php line 116
500 Internal Server Error - ErrorException "><pre class="notranslate"><code class="notranslate">Catchable Fatal Error: Argument 1 passed to AIC\UserBundle\Entity\AnagraficaPersone::setRubriche() must be an instance of Doctrine\Common\Collections\ArrayCollection, array given, called in /Applications/MAMP/htdocs/AIC_22-5-12/vendor/symfony/src/Symfony/Component/Form/Util/PropertyPath.php on line 347 and defined in /Applications/MAMP/htdocs/AIC_22-5-12/src/AIC/UserBundle/Entity/AnagraficaPersone.php line 116
500 Internal Server Error - ErrorException 
</code></pre></div>
<p dir="auto">the incriminated method is the following:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="//AnagraficaPersone.php
    public function setRubriche(ArrayCollection $rubriche) {
        foreach ($rubriche as $rubrica) {
            if($rubrica instanceof Rubrica)
                $rubrica-&gt;setPersona($this);
            else
                throw new InvalidTypeException();
        }
        $this-&gt;rubriche = $rubriche;
    }"><pre class="notranslate"><code class="notranslate">//AnagraficaPersone.php
    public function setRubriche(ArrayCollection $rubriche) {
        foreach ($rubriche as $rubrica) {
            if($rubrica instanceof Rubrica)
                $rubrica-&gt;setPersona($this);
            else
                throw new InvalidTypeException();
        }
        $this-&gt;rubriche = $rubriche;
    }
</code></pre></div>
<p dir="auto">the html code I added via jQuery is equals to that which is generated by Symfony himself but with different ids, from what I understood "symfony/src/Symfony/Component/Form/Util/PropertyPath.php" when handling the data from post, creates an array of objects Rubrica and not an ArrayCollection of Rubrica. I need to tell symfony not to do this, is there a way? Is there any other workaround?<br>
Please excuse me for the poor explanation, if you need anything more to understand this you're wellcome</p>
<p dir="auto">Linuxatico</p>
<table role="table">
<thead>
<tr>
<th>Q</th>
<th>A</th>
</tr>
</thead>
<tbody>
<tr>
<td>Bug report?</td>
<td>no</td>
</tr>
<tr>
<td>Feature request?</td>
<td>yes</td>
</tr>
<tr>
<td>BC Break report?</td>
<td>no</td>
</tr>
<tr>
<td>RFC?</td>
<td>no</td>
</tr>
<tr>
<td>Symfony version</td>
<td>x.y.z</td>
</tr>
</tbody>
</table>
<p dir="auto">Possibility to create a new http kernel event KernelEvents::CONTROLLER_CALL to act in</p>
<p dir="auto"><a href="https://github.com/symfony/http-kernel/blob/master/HttpKernel.php#L151">https://github.com/symfony/http-kernel/blob/master/HttpKernel.php#L151</a> to be replaced for something like this :</p>
<div class="highlight highlight-text-html-php notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="$event = new FilterControllerCallEvent($this, $controller, $arguments, ....);
$this-&gt;dispatcher-&gt;dispatch(KernelEvents::CONTROLLER_CALL, $event);
$response = $event-&gt;getResponse();"><pre class="notranslate"><span class="pl-s1"><span class="pl-c1">$</span>event</span> = <span class="pl-k">new</span> <span class="pl-v">FilterControllerCallEvent</span>(<span class="pl-s1"><span class="pl-c1">$</span><span class="pl-smi">this</span></span>, <span class="pl-s1"><span class="pl-c1">$</span>controller</span>, <span class="pl-s1"><span class="pl-c1">$</span>arguments</span>, ...<span class="pl-c1">.</span>);
<span class="pl-s1"><span class="pl-c1">$</span><span class="pl-smi">this</span></span>-&gt;<span class="pl-c1">dispatcher</span>-&gt;<span class="pl-en">dispatch</span>(<span class="pl-v">KernelEvents</span>::<span class="pl-c1">CONTROLLER_CALL</span>, <span class="pl-s1"><span class="pl-c1">$</span>event</span>);
<span class="pl-s1"><span class="pl-c1">$</span>response</span> = <span class="pl-s1"><span class="pl-c1">$</span>event</span>-&gt;<span class="pl-en">getResponse</span>();</pre></div>
<p dir="auto">I can help with this feature if need.</p>