title: Get only list of ID's from ManyToMany with Doctrine
body: <p>I have a ManyToMany associated field, and I'm in a situation where I'm only trying to get all the ID's without hydrating any of the sub-entities in the field. </p>
  
  <p>I understand there will be a query to aquire the entity references the moment I access the field, and that's fine/expected. But I need to loop through the ID's, but I don't quite know how to get them without doing </p>
  
  <pre><code>$ids = [];
  foreach($mainEntity-&gt;getSubEntities() as $subentity) {
     $ids[] = $subentity-&gt;getId();
  }
  </code></pre>
  
  <p>This also seems to hydrate the sub entity automatically, im assuming because of the <code>foreach</code> loop. This results in a lot of unnecessary queries and impacts page load time.</p>
  
  <p>I have the subentity field marked with <code>EXTRALAZY</code> as well. </p>
  
  <pre><code>/**
   * @var ArrayCollection
   * @ORM\ManyToMany(targetEntity="User", fetch="EXTRA_LAZY")
   * @ORM\JoinTable(name="user_friends")
   */
  protected $friends;
  </code></pre>