Select2 and many-to-many relations
Closed this issue · 1 comments
Hi,
I've a problem with the select2 entity form type: when I use this type for a many-to-many relation, the link between my entities is not persisted whereas it works with a simple 'entity' form
// it works
$this->form->add('eleves_entity', 'entity', array(
'class' => 'Kub\UserBundle\Entity\Eleve',
"multiple" => true,
"expanded" => true,
"property_path" => "eleves",
'query_builder' => function(EleveRepository $er) {
return $er->createQueryBuilder('e')
->orderBy('e.username', 'ASC')
->where('e.niveau = :niveau')
->setParameter('niveau', $this->data->getNiveau())
;
}
));
// it doesn't
$this->form->add('eleves', 'genemu_jqueryselect2_entity', array(
'class' => 'Kub\UserBundle\Entity\Eleve',
"multiple" => true,
"expanded" => true,
'query_builder' => function(EleveRepository $er) {
return $er->createQueryBuilder('e')
->orderBy('e.username', 'ASC')
->where('e.niveau = :niveau')
->setParameter('niveau', $this->data->getNiveau())
;
}
));
I don't think I made a mistake considering that the doc says that we "just have to prefix the type name with genemu_jqueryselect2_* ", so it may be a malfunction of the bundle, that is, by the way, just awesome !
Thank,
Adrien
Hi thanks for sharing ... can you please give more explanation, I have a relation Many-to-Many btw a Video entity and Category entity I'm confused btw your solution and the incomplete doc explanation it gives an error when I follow the doc the error is : "Could not load type "genemu_jquerychosen_category".. thank you