title: Doctrine 2 - entity have collection of another entities via key holder table
body: <p>I want to implement this type of relationship:</p>
  
  <p><img src="https://i.stack.imgur.com/lNE87.jpg" alt="enter image description here"></p>
  
  <p>Class SimpleUser must have a "languages" class property which should contain list of all SimpleLanguage-s that are binded to the current user in the UserLanguages table.</p>
  
  <p>Please look at the classes:</p>
  
  <pre><code>public class SimpleUser {
  
      /**
       * @var integer
       *
       * @ORM\Column(name="id", type="integer")
       * @ORM\Id
       * @ORM\GeneratedValue(strategy="AUTO")
       */
      private $id;
  
      /**
       * @var string
       *
       * @ORM\Column(name="name", type="string", length=50)
       */
      private $name;
  
      // what do I type here? I want to have SimpleLanguage[] here
      private $languages;
  }
  </code></pre>
  
  <hr>
  
  <pre><code> public class SimpleLanguage {
  
      /**
       * @var integer
       *
       * @ORM\Column(name="id", type="integer")
       * @ORM\Id
       * @ORM\GeneratedValue(strategy="AUTO")
       */
      private $id;
  
      /**
       * @var string
       *
       * @ORM\Column(name="name", type="string", length=50)
       */
      private $name;
  }
  </code></pre>
  
  <hr>
  
  <pre><code> public class UserLanguages {
  
      /**
       * @var integer
       *
       * @ORM\Column(name="id", type="integer")
       * @ORM\Id
       * @ORM\GeneratedValue(strategy="AUTO")
       */
      private $id;
  
  
  /**
   * @var integer
   * @ORM\Column(name="user_id", type="integer")
   */
  private $userId;
  
  /**
   * @var integer
   * @ORM\Column(name="language_id", type="integer")
   */
  private $languageId;
  
  /**
   * @var SimpleUser
   *
   * @ManyToOne(targetEntity="SimpleUser")
   * @JoinColumn(name="userId", referencedColumnName="id")
   */
  private $user;
  
  /**
   * @var SimpleLanguage
   *
   * @ManyToOne(targetEntity="SimpleLanguage")
   * @JoinColumn(name="languageId", referencedColumnName="id")
   */
  private $language;
  }
  </code></pre>