title: Undefined index on doctrine m:n relation
body: <p>I have a 'department' and 'newsItem', which are related m:n. Whenever I try to enumerate over a department's newsItems, thus triggering retrieval from the db, I get this error:</p>
  
  <pre>
  at ErrorHandler ->handle (
    '8',
    'Undefined index: newsItems',
    '/.../ufscar_symfony/vendor/doctrine/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php',
    '807',
    array(
      'assoc' => array(
        'fieldName' => 'newsItems',
        'joinTable' => array(),
        'targetEntity' => 'UfscarDfmc\OrgBundle\Entity\NewsItem',
        'mappedBy' => 'newsItems',
        'inversedBy' => null,
        'cascade' => array(),
        'fetch' => '2',
        'type' => '8',
        'isOwningSide' => false,
        'sourceEntity' => 'UfscarDfmc\OrgBundle\Entity\Department',
        'isCascadeRemove' => false,
        'isCascadePersist' => false,
        'isCascadeRefresh' => false,
        'isCascadeMerge' => false,
        'isCascadeDetach' => false
      ),
      'sourceEntity' => object(Department),
      'offset' => null,
      'limit' => null,
      'criteria' => array(),
      'sourceClass' => object(ClassMetadata)
    )
  )
  </pre>
  
  <p>What is especially weird is, that there is another relation in department, to another m:n entity, that just works, and there is no difference in how the mapping is set up, I checked 10 times at least.</p>
  
  <p>The classes and the full stacktrace:</p>
  
  <pre><code>     /**
   * @ORM\Table()
   * @ORM\Entity(repositoryClass="...\OrgBundle\Entity\DepartmentRepository")
   */
  class Department
  {
          /**
       * Inverse Side
       *
       * @ManyToMany(targetEntity="NewsItem", mappedBy="newsItems")
       */
      private $newsItems;
  
      public function __construct()
      {
          $this-&gt;newsItems = new \Doctrine\Common\Collections\ArrayCollection();
      }
      /**
       * Get newsItems
       *
       * @return Doctrine\Common\Collections\Collection 
       */
      public function getNewsItems()
      {
          return $this-&gt;newsItems;
      }
  }
  
  
  class NewsItem
  {
      /**
       * Owning Side
       *
       * @ManyToMany(targetEntity="Department", inversedBy="newsItems")
       * @JoinTable(name="newsItems_departments",
       *      joinColumns={@JoinColumn(name="newsItem_id", referencedColumnName="id")},
       *      inverseJoinColumns={@JoinColumn(name="department_id", referencedColumnName="id")}
       *      )
       */
      private $departments;
  
      public function __construct(){
          $this-&gt;departments = new \Doctrine\Common\Collections\ArrayCollection();
      }
  
      /**
       * Get departments
       *
       * @return Doctrine\Common\Collections\Collection 
       */
      public function getDepartments()
      {
          return $this-&gt;departments;
      }
  }
  
  
  public function showAction($slug)
  {
      $em = $this-&gt;getDoctrine()-&gt;getEntityManager();
      $entity = $em-&gt;getRepository('UfscarDfmcOrgBundle:Department')-&gt;findOneBySlug($slug);
  
      return array(
          'entity' =&gt; $entity,
          'newsItems' =&gt; $entity-&gt;getNewsItems(), # enumerating over this gives the error
      );
  }
  </code></pre>
  
  <pre>
  at ErrorHandler ->handle ('8', 'Undefined index: newsItems', '/.../vendor/doctrine/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php', '807', array('assoc' => array('fieldName' => 'newsItems', 'joinTable' => array(), 'targetEntity' => 'UfscarDfmc\OrgBundle\Entity\NewsItem', 'mappedBy' => 'newsItems', 'inversedBy' => null, 'cascade' => array(), 'fetch' => '2', 'type' => '8', 'isOwningSide' => false, 'sourceEntity' => 'UfscarDfmc\OrgBundle\Entity\Department', 'isCascadeRemove' => false, 'isCascadePersist' => false, 'isCascadeRefresh' => false, 'isCascadeMerge' => false, 'isCascadeDetach' => false), 'sourceEntity' => object(Department), 'offset' => null, 'limit' => null, 'criteria' => array(), 'sourceClass' => object(ClassMetadata))) 
  in /.../vendor/doctrine/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php at line 807   
  at BasicEntityPersister ->getManyToManyStatement (array('fieldName' => 'newsItems', 'joinTable' => array(), 'targetEntity' => 'UfscarDfmc\OrgBundle\Entity\NewsItem', 'mappedBy' => 'newsItems', 'inversedBy' => null, 'cascade' => array(), 'fetch' => '2', 'type' => '8', 'isOwningSide' => false, 'sourceEntity' => 'UfscarDfmc\OrgBundle\Entity\Department', 'isCascadeRemove' => false, 'isCascadePersist' => false, 'isCascadeRefresh' => false, 'isCascadeMerge' => false, 'isCascadeDetach' => false), object(Department)) 
  in /.../vendor/doctrine/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php at line 778   
  at BasicEntityPersister ->loadManyToManyCollection (array('fieldName' => 'newsItems', 'joinTable' => array(), 'targetEntity' => 'UfscarDfmc\OrgBundle\Entity\NewsItem', 'mappedBy' => 'newsItems', 'inversedBy' => null, 'cascade' => array(), 'fetch' => '2', 'type' => '8', 'isOwningSide' => false, 'sourceEntity' => 'UfscarDfmc\OrgBundle\Entity\Department', 'isCascadeRemove' => false, 'isCascadePersist' => false, 'isCascadeRefresh' => false, 'isCascadeMerge' => false, 'isCascadeDetach' => false), object(Department), object(PersistentCollection)) 
  in /.../vendor/doctrine/lib/Doctrine/ORM/UnitOfWork.php at line 2088    
  at UnitOfWork ->loadCollection (object(PersistentCollection)) 
  in /.../vendor/doctrine/lib/Doctrine/ORM/PersistentCollection.php at line 207    
  at PersistentCollection ->initialize () 
  in /.../vendor/doctrine/lib/Doctrine/ORM/PersistentCollection.php at line 474    
  at PersistentCollection ->count () 
  in at line     
  at count (object(PersistentCollection)) 
  in /.../src/UfscarDfmc/OrgBundle/Controller/DepartmentController.php at line 53    
  at DepartmentController ->showAction ('graduacao') 
  in at line
  </pre>