Is it possible to use collection in form type while calling a relationship field?
Here's what im trying to do:
I have a relationship between Candidates Entity & Districts Entity where a candidate can belong to multiple districts.
I set up the form type this way:
candidates type
$builder
->add('name')
->add('district', 'collection', array('type'=>new districtsChoiceType()))
districtschoice type
$builder
->add('candidate', 'entity', array(
'class' => 'CMSElectionsBundle:districts',
'query_builder' => function(EntityRepository $get) {
return $get->createQueryBuilder('p')->where('p.status = 1')->orderBy('p.id', 'ASC');
}, 'property' => 'name', 'label' => ' '))
So im facing 2 problems here:
- when i want to create a new candidate, the district field appears empty/
when i try to edit an existing candidate, i get the following error:
Expected argument of type "array or (\Traversable and \ArrayAccess)", "Proxies\__CG__\CMS\ElectionsBundle\Entity\districts" given