4
votes

I created an embedded collection of another entity in a form, the idea would be that when you edit or erase up to 'demand' also would edit the 'products' that belong to it, my creating form is ok, but the editing it gives the error :

Catchable Fatal Error: Argument 1 passed to MaisAlimentos\DemandaBundle\Entity\Demanda::setProdutosDemanda() must be an instance of Doctrine\Common\Collections\ArrayCollection, instance of Doctrine\ORM\PersistentCollection given, called in /var/www/maa/vendor/symfony/src/Symfony/Component/Form/Util/PropertyPath.php on line 347 and defined in /var/www/maa/src/MaisAlimentos/DemandaBundle/Entity/Demanda.php line 130

I read on some forums, the solution is remove type of the setter, I got other error:

Catchable Fatal Error: Object of class Doctrine\ORM\PersistentCollection could not be converted to string in /var/www/maa/src/MaisAlimentos/DemandaBundle/Entity/Demanda.php line 136

my code

http://pastebin.com/WeGcHyYL

1

1 Answers

2
votes

OK, so you've found the solution for your original problem.

The second one comes from a typo/copy-paste error.

In the line 162 on your pastebin code:

$this->$produtosDemanda = $produtosDemanda;

should be

$this->produtosDemanda = $produtosDemanda;

So no $ sign after $this->.