title: How can i execute findBy on many to many relation in Doctrine?
body: <p>I have an entity like below:</p>
  
  <pre><code>&lt;?php
  /** @Entity */
  class User
  {
      // ...
  
      /**
       * Many Users have Many Groups.
       * @ManyToMany(targetEntity="Group", inversedBy="users")
       * @JoinTable(name="users_groups")
       */
      private $groups;
  
      public function __construct() {
          $this-&gt;groups = new \Doctrine\Common\Collections\ArrayCollection();
      }
  
      // ...
  }
  
  /** @Entity */
  class Group
  {
      // ...
      /**
       * Many Groups have Many Users.
       * @ManyToMany(targetEntity="User", mappedBy="groups")
       */
      private $users;
  
      public function __construct() {
          $this-&gt;users = new \Doctrine\Common\Collections\ArrayCollection();
      }
  
      // ...
  }
  </code></pre>
  
  <p><a href="https://www.doctrine-project.org/projects/doctrine-orm/en/2.6/reference/association-mapping.html#many-to-many-bidirectional" rel="nofollow noreferrer">https://www.doctrine-project.org/projects/doctrine-orm/en/2.6/reference/association-mapping.html#many-to-many-bidirectional</a></p>
  
  <p>I have related Repositories to those entities.
  When there is one to many relationship it is quite easy to get related object because you can easily execute something like:</p>
  
  <pre><code>/** @var RelatedEntity $relatedEntity*/
  $this-&gt;findBy('relatedObject'=&gt;$relatedEntity);
  </code></pre>
  
  <p>When i try to execute it on Entities showed above instead of gathering objects thorough lets say user_group table it try to find user_group column inside user table. It generates error like:</p>
  
  <blockquote>
    <p>An exception occurred while executing 'SELECT t0.id AS id_1, t0.created_at AS created_at_2, t0.updated_at AS updated_at_3, t0.title AS title_4, t0.text AS text_5 FROM user t0 WHERE user_group.group_id = ?' with params ["8192ed63-5d07-4c99-8902-006a3aa986e7"]:</p>
    
    <p>SQLSTATE[42P01]: Undefined table: 7 ERROR: missing FROM-clause entry for table "user_group"</p>
  </blockquote>
  
  <p>I have no idea how it should be done properly. What have I missed?</p>