You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
I created two entities using a ManyToMany-relation and want to edit the relation from both of the entites using an AssocationField.
(e.g. User and Group, I want to be able to edit the User and assign it to many groups as well as edit the Group and assign many users to it)
What happens is that the relation is only saved "one way". I added the corresponding field to both CrudControllers, the field is shown on both edit-pages but will only save the relation when the entity is saved that has the "inversedBy"-part. The "mappedBy"-entity will not save the data.
I have tried to add "ORM\JoinTable" but that either result in an "table exists"-error or in two different relation-tables being created (user_group and group_user) which will save the relation but not making it visible to the other entity (so I end up having two ManyToMany-relations).
To Reproduce
Version used is 4.0.2, to reproduce create to entities:
Then add the relation as an AssociationField in the CrudControllers: yield AssociationField::new('users'); in the GroupCrudController and yield AssociationField::new('groups'); in the UserCrudController.
The text was updated successfully, but these errors were encountered:
You are absolutely right, thanks a lot for pointing me in the right direction!
With symfony 5 the additions described in the symfonycast are already included by default, so the solution is to just add ->setFormTypeOption('by_reference', false) to the "mappedBy"-part of the relation.
Describe the bug
I created two entities using a ManyToMany-relation and want to edit the relation from both of the entites using an AssocationField.
(e.g. User and Group, I want to be able to edit the User and assign it to many groups as well as edit the Group and assign many users to it)
What happens is that the relation is only saved "one way". I added the corresponding field to both CrudControllers, the field is shown on both edit-pages but will only save the relation when the entity is saved that has the "inversedBy"-part. The "mappedBy"-entity will not save the data.
I have tried to add "ORM\JoinTable" but that either result in an "table exists"-error or in two different relation-tables being created (user_group and group_user) which will save the relation but not making it visible to the other entity (so I end up having two ManyToMany-relations).
To Reproduce
Version used is 4.0.2, to reproduce create to entities:
Then add the relation as an AssociationField in the CrudControllers:
yield AssociationField::new('users');
in the GroupCrudController andyield AssociationField::new('groups');
in the UserCrudController.The text was updated successfully, but these errors were encountered: