title: Symfony2 && mongodb simple reference
body: <p>he guys,</p>
  
  <p>i want to make a simple reference on mongodb documents using symfony2.</p>
  
  <p>i have this two documents and want to store picture references into the requests document. it works for me, if i have only the picture ids in the requests document.</p>
  
  <p>so i need the follow:</p>
  
  <p>can everyone change the document files and make and extends the custum call to get all pictures as object from the requests (picture array)?</p>
  
  <p>my original files:</p>
  
  <p>Document Pictures:</p>
  
  <pre><code>&lt;?php
  
  namespace TestBundle\Document;
  use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;
  
  /**
   * @MongoDB\Document(repositoryClass="TestBundle\Repository\RequestsRepository")
   */
  class Requests
  {
      /**
       * @MongoDB\Id
       */
      protected $id;
  
      /**
       * @MongoDB\String
       */
      protected $title;
  
      public function setId($id)
      {
          $this-&gt;id = $id;
      }
  
      public function getId()
      {
          return $this-&gt;id;
      }
  
      public function setTitle($title)
      {
          $this-&gt;title = $title;
      }
  
      public function getTitle()
      {
          return $this-&gt;title;
      }
  }
  </code></pre>
  
  <p>Document Pictures:</p>
  
  <pre><code>&lt;?php
  
  namespace TestBundle\Document;
  use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;
  
  /**
   * @MongoDB\Document(repositoryClass="TestBundle\Repository\PicturesRepository")
   */
  class Pictures
  {
      /**
       * @MongoDB\Id
       */
      protected $id;
  
      /**
       * @MongoDB\String
       */
      protected $filename;
  
      public function setId($id)
      {
          $this-&gt;id = $id;
      }
  
      public function getId()
      {
          return $this-&gt;id;
      }
  
      public function setFilename($filename)
      {
          $this-&gt;filename = $filename;
      }
  
      public function getTitle()
      {
          return $this-&gt;filename;
      }
  }
  </code></pre>
  
  <p>My Basic Calls:</p>
  
  <pre><code>$dm = $this-&gt;get('doctrine.odm.mongodb.document_manager');
  $request = $dm-&gt;getRepository('TestBundle:Requests')-&gt;find($requestId);
  </code></pre>
  
  <p>To my tests:</p>
  
  <p>i added in the requests document the follow:</p>
  
  <pre><code>/**
   * @MongoDB\ReferenceMany(targetDocument="Pictures",cascade={"persist"},simple="true")
   */
  protected $pictures = array();
  public function setPictures($pictures)
  {
      $this-&gt;pictures[] = $pictures;
  }
  
  public function getPictures()
  {
      return $this-&gt;pictures;
  
  }
  </code></pre>
  
  <p>and added pictures like this:</p>
  
  <pre><code>$dm     = $this-&gt;get('doctrine.odm.mongodb.document_manager');
  $photo   = $dm-&gt;getRepository('TestBundle:Pictures')-&gt;find($photoId);
  
  $dm1 = $this-&gt;get('doctrine.odm.mongodb.document_manager');
  $request = $dm1-&gt;getRepository('TestBundle:Requests')-&gt;find($requestId);
  
  $request-&gt;setPictures($photo);
  $dm1-&gt;flush();
  </code></pre>
  
  <p>this works - but i cannot get the pictures by loading the document.</p>
  
  <p>my code to load:</p>
  
  <pre><code>$dm1 = $this-&gt;get('doctrine.odm.mongodb.document_manager');
  $request = $dm1-&gt;getRepository('TestBundle:Requests')-&gt;find($requestId);
  
  $pictures = $request-&gt;getPictures();
  
  foreach($pictures as $picture)
  {
      print $picture-&gt;getId();         
  }
  </code></pre>
  
  <p>THIS WILL NOT WORK. i become the follow error:</p>
  
  <blockquote>
    <p>Fatal error: Doctrine\ODM\MongoDB\Proxy\ProxyFactory::getProxy():
    Failed opening required
    '.../app/cache/dev/doctrine/odm/mongodb/Proxies/_<em>CG</em>_TestBundleDocumentPictures.php'
    (include_path='.:.../library:/usr/local/zend/share/pear') in
    ..../test/vendor/doctrine-mongodb-odm/lib/Doctrine/ODM/MongoDB/Proxy/ProxyFactory.php
    on line 100</p>
  </blockquote>
  
  <p><strong>thanks, jan</strong></p>