title: Doctrine - Store ArrayCollection keys
body: <p>Whenever I use an ArrayCollection with Doctrine ORM (2.3, PHP > 5.4), and associate the object values with a key in the collection (such as when using the <code>set</code> method), the values get stored correctly in the database. But when I want to retrieve the collection from the entity, the keys don't get retrieved and instead they use a numeric index.</p>
  
  <p>For instance, if I have the following classes:</p>
  
  <pre><code>/** @Entity */
  class MyEntity
  {
      /** @OneToMany(targetEntity="MyOtherEntity", mappedBy="mainEntity") */
      private $myArray;
  
      public function __construct()
      {
          $this-&gt;myArray = new ArrayCollection();
      }
  
      public function addOtherEntity($key, $value)
      {
          $this-&gt;myArray-&gt;set($key, $value);
      }
  
      ...
  }
  
  /** @Entity */
  class MyOtherEntity
  {
      /** @ManyToOne(targetEntity="MyEntity", inversedBy="myArray") */
      private $mainEntity;
      ...
  }
  </code></pre>
  
  <p>The <code>set</code> method works properly, but when I retrieve the information the keys in <code>$myArray</code> are gone.</p>
  
  <p>How do I make the ORM remember properly the keys? Thank you beforehand.</p>