I have a problem using forms in Symfony 2 with mongoDB documents.
I'm trying to have a form that will represent my first document (Post) with a relation oneToMany to Tags (reference)
The relation is declared like this :
/**
* @Assert\Collection
* @MongoDB\ReferenceMany(targetDocument="Acme\ManagerBundle\Document\Tags")
*/
protected $tags;
A tag has an Id and a Name.
I have tried a lot of things to make it work
$form = $this->createFormBuilder($tag)->add('tags', 'choice', array('choices' => $tags, 'multiple' => true, 'expanded' => true, 'empty_value' => true, ))
The form show the choices but once its submited the form is not valid and keep showing thhis error :
"The fields "0", "1", "2" were not expected"
I've also tried this : symfony2 form choice and mongodb
But the use of it is kinda confusing
UPDATE
This is what i get after the post is submited :
object(Doctrine\Common\Collections\ArrayCollection)#795 (1) {
["_elements":"Doctrine\Common\Collections\ArrayCollection":private]=>
array(2) {
[0]=>
object(Acme\ManagerBundle\Document\Tags)#723 (2) {
["id":protected]=>
string(24) "4f7a0eb1ecd111b99c3d2f25"
["name":protected]=>
string(6) "Fruits"
}
[1]=>
object(Acme\ManagerBundle\Document\Tags)#720 (2) {
["id":protected]=>
string(24) "4f7a0ec7ecd111b99c3d2f26"
["name":protected]=>
string(10) "Vegetables"
}
}
}
So now i understand why i have "The fields "0", "1", "2" were not expected" but i dont understand why Symfony doesn't process it.
I've been looking a the possible bundles but nothing
I have no idea how to have a nice form that will hydrate my object and the related objects, does anyone has a solution for this issue or other idea to solve this?
Thanks a bunch !