title: Symfony 5 how to automatically send the current user in an update with a ManyToMany relationship
body: <p>I want my current user to enroll in a rate.</p>
  <pre><code>```
  /**
   * @ORM\Column(type=&quot;string&quot;, length=255)
   */
  private $name;
  
  /**
   * @ORM\ManyToOne(targetEntity=&quot;App\Entity\User&quot;, inversedBy=&quot;matters&quot;)
   * @ORM\JoinColumn(nullable=false)
   */
  private $user;
  
  /**
   * @ORM\OneToMany(targetEntity=&quot;App\Entity\Note&quot;, mappedBy=&quot;matter&quot;)
   */
  private $notes;
  
  /**
   * @ORM\ManyToMany(targetEntity=&quot;App\Entity\User&quot;, inversedBy=&quot;studentsMatters&quot;)
   */
  private $student;
  ```
  </code></pre>
  <p>When he presses &quot;update&quot;, the ManyToMany relationship must send the current user.
  In my controller, I am trying to send the current user</p>
  <pre><code>/**
   * @Route(&quot;/{id}/edit&quot;, name=&quot;student_edit&quot;, methods={&quot;GET&quot;,&quot;POST&quot;})
   */
  public function edit(Request $request, Matter $matter): Response
  {
      $form = $this-&gt;createForm(StudentType::class, $matter);
      $form-&gt;handleRequest($request);
      $user = $this-&gt;getUser();
      $matter-&gt;setStudent($this-&gt;getUser());
  
      if ($form-&gt;isSubmitted() &amp;&amp; $form-&gt;isValid()) {
          $this-&gt;getDoctrine()-&gt;getManager()-&gt;flush();
  
          return $this-&gt;redirectToRoute('student_index');
      }
  
      return $this-&gt;render('student/edit.html.twig', [
          'matter' =&gt; $matter,
          'form' =&gt; $form-&gt;createView(),
      ]);
  }
  </code></pre>
  <p>but it doesn't works.</p>
  <p>How I do to get current user?</p>