I'm having a many-to-many relationship between the tables User
and Group
. Some of the groups are assigned to the users automatically based on their type. Other groups can be managed by the administrators using the user edit form.
In order to achieve that the administrators can only manage the groups that the are supposed to, I'm using the query_builder
option of the EntityType
form type.
$builde->add('groups', EntityType::class, [
// ...
'query_builder' => function (EntityRepository $er) {
return $er->createQueryBuilder('g')
->where('g.type = ?1')
->setParameter(1, 'user_managed');
},
'multiple' => true,
// ...
]);
My problem is now that up on saving the user entity only the groups that were selected in the form are associated to the user and that all associations that were not displayed are deleted.
Is there a way to only change the association of the displayed groups to the user instead of all of them?
Thanks