Reputation: 21
I have a form that has 3 entites (Obras, FechaObra and HorarioObra) with one to many relationship. One Obra may have many FechaObra and one FechaObra may have many HorarioObra. but I made tha form as told in symfony.com/doc/current/cookbook/form/form_collections.html but it gives me this error:
Catchable Fatal Error: Argument 1 passed to Acme\ReservasBundle\Entity\FechaObra::setHorariosobra() must implement interface Doctrine\Common\Collections\Collection, array given, called in /var/www/html/grisar/entradas/vendor/symfony/symfony/src/Symfony/Component/PropertyAccess/PropertyAccessor.php on line 410 and defined
I already defined horariosobra as an arraycollection, but it keeps giving me that error.
The source code of the bundle is in: github.com/javiermarcon/tickets/tree/master/src/Acme/ReservasBundle
Does anyone know why is giving me that error? Thanks
Upvotes: 0
Views: 3960
Reputation: 20191
Remove strong typed \Doctrine\Common\Collections\Collection
from setter method:
public function setHorariosobra($horariosobra)
{
// Be sure to "use" ArrayCollection class
$this->horariosobra = new ArrayCollection($horariosobra);
foreach ($horariosobra as $horarioobra) {
$horarioobra->setObra($this);
}
}
The should fix things. Remember, Forms
component need not to know about Doctrine
- it's entirely up to you to enforce usage of entities. Therefore, submitted data to setter method is generic array rather than Doctrine
's Collection
Upvotes: 1