title: ZF2 - How to use the Hydrator/exchangeArray() to populate a nested object
body: <p>I've got an object with values that are stored in my database. My object also contains another object which is stored in the database using just the ID of it (foreign key).</p>
  
  <p><a href="http://framework.zend.com/manual/2.0/en/modules/zend.stdlib.hydrator.html">http://framework.zend.com/manual/2.0/en/modules/zend.stdlib.hydrator.html</a></p>
  
  <p>Before the <code>Hydrator/exchangeArray</code> functionality in ZF2 you would use a Mapper to grab everything you need to create the object. Now I'm trying to eliminate this extra layer by just using <code>Hydration/exchangeArray</code> to populate my objects but am a bit stuck on creating the nested object.</p>
  
  <p>Should my entity have the Inner object's table injected into it so I can create it if the ID of it is passed to my 'exchangeArray' ?</p>
  
  <p>Here are example entities as an example.</p>
  
  <pre><code>// Village
  id, name, position, square_id
  
  // Map Square
  id, name, type
  </code></pre>
  
  <p>Upon sending square_id to my Village's exchangeArray() function. It would get the mapTable and use hydrator to pull in the square using the ID I have.</p>
  
  <p>It doesn't seem right to be to have mapper instances inside my entity as I thought they should be disconnected from anything but it's own entity specific parameters and functionality?</p>