title: Why is my PersistentCollection empty?
body: <p>I'm using the Symfony 3 Framework with Doctrine and MongoDB.</p>
  
  <p>I've two documents that are in an OneToMany relationship.</p>
  
  <pre><code>/**
   * Class Waypoint
   * @package AppBundle\Document
   * @MongoDB\Document(collection="waypoints", repositoryClass="AppBundle\Repository\WaypointRepository")
   */
  class Waypoint
  {
      /**
       * @var int
       *
       * @MongoDB\Id(strategy="auto")
       */
      private $id;
  
      /**
       * @var ArrayCollection
       * @MongoDB\ReferenceMany(targetDocument="Comment", cascade={"delete"})
       */
      private $comments;
  
  }
  
  **
   * Class Comment
   * @package AppBundle\Document
   * @MongoDB\Document(collection="comments", repositoryClass="AppBundle\Repository\CommentRepository")
   */
  class Comment
  {
  
      /**
       * @var int
       *
       * @MongoDB\Id(strategy="auto")
       */
      private $id;
  
      /**
       * @var Waypoint
       *
       * @MongoDB\ReferenceOne(targetDocument="Waypoint", inversedBy="comments")
       * @Assert\NotBlank()
       */
      private $waypoint;
  }
  </code></pre>
  
  <p>Now I'm getting a part of my <code>Waypoint</code> entries from an repository query and want to display them with twig.</p>
  
  <pre><code>/**
   * WaypointRepository
   *
   * This class was generated by the Doctrine ORM. Add your own custom
   * repository methods below.
   */
  class WaypointRepository extends DocumentRepository
  {
      public function getWaypointsForCruiseByPage(Cruise $cruise, $page)
      {
          $displayLimit = 10;
          $amountToSkip = 0;
  
          if ($page &gt; 1)
          {
              $amountToSkip = ($page -1) * $displayLimit;
          }
  
          $qb = $this-&gt;createQueryBuilder()
              -&gt;select()
              -&gt;field('cruise')-&gt;equals($cruise)
              -&gt;field('isAutoWaypoint')-&gt;equals(false)
              -&gt;sort('date', -1)
              -&gt;skip($amountToSkip)
              -&gt;limit($displayLimit)
          ;
  
          $qb
              -&gt;addOr($qb-&gt;expr()-&gt;field('hasImage')-&gt;equals(true))
              -&gt;addOr($qb-&gt;expr()-&gt;field('hasAudio')-&gt;equals(true))
              -&gt;addOr($qb-&gt;expr()-&gt;field('description')-&gt;notEqual(''))
          ;
  
          return $qb-&gt;getQuery()-&gt;toArray();
      }
  }
  </code></pre>
  
  <p>Now, I'm trying to do <code>{{ waypoint.comments.count }}</code> or <code>{{ waypoint.comments|length }}</code> will always be 0, even if I'm having datasets in my MongoDB collection.</p>
  
  <p>If I'm getting the comments over the CommentRepository by the ID of the Waypoint I'm getting the expected results. </p>
  
  <pre><code>// returns the expected results
  public function getAllCommentsForWaypoint(Waypoint $waypoint)
  {
      return $this-&gt;createQueryBuilder()
          -&gt;select()
          -&gt;field('waypoint')-&gt;equals($waypoint)
          -&gt;getQuery()-&gt;toArray()
      ;
  }
  </code></pre>
  
  <p>The mapping is fine as far as I can tell, no flaws or errors to find.</p>
  
  <p>Why is the PersistentCollection empty, event though informations are there in the collection? </p>