0

I've created a many to many relation and generated crud via command line. I have Users and Groups.

USER
    /**
     * @ORM\ManyToMany(targetEntity="Grup", mappedBy="users")
     * @ORM\JoinTable(name="user_has_grup",
     *     joinColumns={@ORM\JoinColumn(name="grup_id", referencedColumnName="id")},
     *     inverseJoinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="id")}
     * )
     */
    protected $grups;

Grup
    /**
     * @ORM\ManyToMany(targetEntity="User", inversedBy="grups")
     * @ORM\JoinTable(name="user_has_grup",
     *     joinColumns={@ORM\JoinColumn(name="grup_id", referencedColumnName="id")},
     *     inverseJoinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="id")}
     * )
     */
    protected $users;

When i create user group show up but i can't assign user to group. Still when i go to edit Group i can assign User to it and its works well.

What do I need to change, if i want to be able do it in both directions? Is there any Doctrine Entity change or in controller ?

Pascal
  • 1,288
  • 8
  • 13
user2217288
  • 529
  • 2
  • 14
  • 26

1 Answers1

0

Don't know if it's your problem because not enough code...
But i think this can help : Symfony2-Doctrine: ManyToMany relation is not saved to database
And official documentation :Owning and Inverse Side on a ManyToMany association

Community
  • 1
  • 1
label55
  • 125
  • 7
  • solved: here is the answer http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/unitofwork-associations.html The inverse side has to use the mappedBy attribute of the OneToOne, OneToMany, or ManyToMany mapping declaration. The mappedBy attribute contains the name of the association-field on the owning side. The owning side has to use the inversedBy attribute of the OneToOne, ManyToOne, or ManyToMany mapping declaration. The inversedBy attribute contains the name of the association-field on the inverse-side. – user2217288 May 10 '14 at 12:26