title: Apigility with Doctrine 2 ODM MongoDB
body: <p>When i get entity from my API i got error:</p>
  
  <p><strong>PHP Fatal error:  Call to a member function createQuery() on a non-object in /Sites/system.local/vendor/zfcampus/zf-apigility-doctrine/src/Server/Resource/DoctrineResource.php on line 442</strong></p>
  
  <p>DoctrineResource.php (function on line 442 - fetchAll):</p>
  
  <pre class="lang-php prettyprint-override"><code>    /**
       * Fetch all or a subset of resources
       *
       * @see    Apigility/Doctrine/Server/Resource/AbstractResource.php
       * @param  array $data
       * @return ApiProblem|mixed
       */
      public function fetchAll($data = array())
      {
          // Build query
          $queryProvider = $this-&gt;getQueryProvider('fetch_all');
          $queryBuilder = $queryProvider-&gt;createQuery($this-&gt;getEvent(), $this-&gt;getEntityClass(), $data);
  
          if ($queryBuilder instanceof ApiProblem) {
              // @codeCoverageIgnoreStart
              return $queryBuilder;
          }
              // @codeCoverageIgnoreEnd
  
          // Run fetch all pre with query builder
          $event = new DoctrineResourceEvent(DoctrineResourceEvent::EVENT_FETCH_ALL_PRE, $this);
          $event-&gt;setQueryBuilder($queryBuilder);
          $event-&gt;setResourceEvent($this-&gt;getEvent());
          $event-&gt;setEntity($this-&gt;getEntityClass());
          $eventManager = $this-&gt;getEventManager();
          $response = $eventManager-&gt;trigger($event);
          if ($response-&gt;last() instanceof ApiProblem) {
              return $response-&gt;last();
          }
  
          $adapter = $queryProvider-&gt;getPaginatedQuery($queryBuilder);
          $reflection = new \ReflectionClass($this-&gt;getCollectionClass());
          $collection = $reflection-&gt;newInstance($adapter);
  
          $results = $this-&gt;triggerDoctrineEvent(DoctrineResourceEvent::EVENT_FETCH_ALL_POST, null, $collection);
          if ($results-&gt;last() instanceof ApiProblem) {
              return $results-&gt;last();
          }
  
          // Add event to set extra HAL data
          $entityClass = $this-&gt;getEntityClass();
          StaticEventManager::getInstance()-&gt;attach(
              'ZF\Rest\RestController',
              'getList.post',
              function ($e) use ($queryProvider, $entityClass, $data) {
                  $halCollection = $e-&gt;getParam('collection');
                  $collection = $halCollection-&gt;getCollection();
  
                  $collection-&gt;setItemCountPerPage($halCollection-&gt;getPageSize());
                  $collection-&gt;setCurrentPageNumber($halCollection-&gt;getPage());
  
                  $halCollection-&gt;setAttributes(
                      array(
                      'count' =&gt; $collection-&gt;getCurrentItemCount(),
                      'total' =&gt; $collection-&gt;getTotalItemCount(),
                      'collectionTotal' =&gt; $queryProvider-&gt;getCollectionTotal($entityClass),
                      )
                  );
  
                  $halCollection-&gt;setCollectionRouteOptions(
                      array(
                      'query' =&gt; ArrayUtils::iteratorToArray($data)
                      )
                  );
              }
          );
  
          return $collection;
      }
  </code></pre>
  
  <p>My composer.json:</p>
  
  <pre class="lang-javascript prettyprint-override"><code>{
      "name": "zfcampus/zf-apigility-skeleton",
      "description": "Skeleton Application for Apigility",
      "type": "library",
      "license": "BSD-3-Clause",
      "keywords": [
          "api",
          "apigility",
          "framework",
          "zf2"
      ],
      "homepage": "http://apigility.org/",
      "support": {
          "email": "apigility-users@zend.com",
          "irc": "irc://irc.freenode.net/apigility",
          "source": "https://github.com/zfcampus/zf-apigility-skeleton",
          "issues": "https://github.com/zfcampus/zf-apigility-skeleton/issues"
      },
      "config": {
        "process-timeout": 5000
      },
      "extra": {
        "branch-alias": {
          "dev-master": "1.0-dev",
          "dev-develop": "1.1-dev"
        }
      },
      "repositories": [
        {
          "type": "git",
          "url": "https://github.com/stefanotorresi/zf-hal.git"
        }
      ],
      "require": {
        "php": "&gt;=5.3.23",
        "zendframework/zendframework": "&gt;=2.3.2,&lt;3.0.0",
        "zfcampus/zf-apigility": "~1.0",
        "zfcampus/zf-apigility-documentation": "~1.0",
        "zfcampus/zf-development-mode": "~2.0",
        "zfcampus/zf-hal": "dev-master#57980316543edfa329d7b1d65106fb73988c60ad",
        "zfcampus/zf-doctrine-querybuilder": "0.1.*"
      },
      "require-dev": {
        "zendframework/zftool": "dev-master",
        "zendframework/zend-developer-tools": "dev-master",
        "zfcampus/zf-apigility-admin": "~1.0",
        "zfcampus/zf-apigility-welcome": "~1.0",
        "doctrine/doctrine-mongo-odm-module": "dev-master",
        "zfcampus/zf-apigility-doctrine": "dev-master",
        "doctrine/mongodb-odm": "dev-master",
        "doctrine/doctrine-module": "dev-master",
        "zfcampus/zf-deploy": "~1.0"
      }
  }
  </code></pre>
  
  <p>My module.config.php:</p>
  
  <pre class="lang-php prettyprint-override"><code>&lt;?php
  
  return array(
  
      'doctrine' =&gt; array(
          'driver' =&gt; array(
              'my_driver' =&gt; array(
                  'class' =&gt; 'Doctrine\\ODM\\MongoDB\\Mapping\\Driver\\AnnotationDriver',
                  'namespace' =&gt; 'My\\Entity',
                  'paths' =&gt; array(
                      0 =&gt; __DIR__ . '/../src/My/Entity',
                  ),
              ),
              'odm_default' =&gt; array(
                  'drivers' =&gt; array(
                      'My\\Entity' =&gt; 'my_driver',
                  ),
              ),
          ),
      ),
  
      'service_manager' =&gt; array(
          'factories' =&gt; array(
              'My\\V1\\Rest\\Track\\TrackResource' =&gt; 'My\\V1\\Rest\\Track\\TrackResourceFactory',
              'ZF\\Apigility\\Doctrine\\Server\\Resource\\DoctrineResource' =&gt; 'ZF\\Apigility\\Doctrine\\Server\\Resource\\DoctrineResourceFactory',
          ),
      ),
  
  
      'zf-apigility-doctrine-query-provider' =&gt; array(
          'invokables' =&gt; array(
              'default_odm' =&gt; 'My\\Query\\Provider\\DefaultOdm',
              'update' =&gt; 'My\\Query\\Provider\\Update',
              'delete' =&gt; 'My\\Query\\Provider\\Delete',
          ),
      ),
  
      'zf-apigility-doctrine-query-create-filter' =&gt; array(
          'invokables' =&gt; array(
              'default' =&gt; 'My\\Query\\CreateFilter\\DefaultCreateFilter',
          ),
      ),
  
      'router' =&gt; array(
          'routes' =&gt; array(
              'my.rest.track' =&gt; array(
                  'type' =&gt; 'Segment',
                  'options' =&gt; array(
                      'route' =&gt; '/my/track[/:track_id]',
                      'defaults' =&gt; array(
                          'controller' =&gt; 'My\\V1\\Rest\\Track\\Controller',
                      ),
                  ),
              ),
          ),
      ),
  
      'zf-versioning' =&gt; array(
          'uri' =&gt; array(
              0 =&gt; 'my.rest.track',
          ),
      ),
  
      'zf-rest' =&gt; array(
          'My\\V1\\Rest\\Track\\Controller' =&gt; array(
              'listener' =&gt; 'My\\V1\\Rest\\Track\\TrackResource',
              'route_name' =&gt; 'my.rest.track',
              'route_identifier_name' =&gt; 'track_id',
              'collection_name' =&gt; 'track',
              'entity_http_methods' =&gt; array(
                  0 =&gt; 'GET',
                  1 =&gt; 'PATCH',
                  2 =&gt; 'PUT',
                  3 =&gt; 'DELETE',
              ),
              'collection_http_methods' =&gt; array(
                  0 =&gt; 'GET',
                  1 =&gt; 'POST',
              ),
              'collection_query_whitelist' =&gt; array(),
              'page_size' =&gt; 25,
              'page_size_param' =&gt; null,
              'entity_class' =&gt; 'My\\Entity\\Track',
              'collection_class' =&gt; 'My\\V1\\Rest\\Track\\TrackCollection',
              'service_name' =&gt; 'track',
          ),
      ),
      'zf-content-negotiation' =&gt; array(
          'controllers' =&gt; array(
              'My\\V1\\Rest\\Track\\Controller' =&gt; 'HalJson',
          ),
          'accept_whitelist' =&gt; array(
              'My\\V1\\Rest\\Track\\Controller' =&gt; array(
                  0 =&gt; 'application/vnd.my.v1+json',
                  1 =&gt; 'application/hal+json',
                  2 =&gt; 'application/json',
              ),
          ),
          'content_type_whitelist' =&gt; array(
              'My\\V1\\Rest\\Track\\Controller' =&gt; array(
                  0 =&gt; 'application/vnd.my.v1+json',
                  1 =&gt; 'application/json',
              ),
          ),
      ),
      'zf-hal' =&gt; array(
          'metadata_map' =&gt; array(
              'My\\V1\\Rest\\Track\\Track' =&gt; array(
                  'entity_identifier_name' =&gt; 'id',
                  'route_name' =&gt; 'My.rest.track',
                  'route_identifier_name' =&gt; 'track_id',
                  'hydrator' =&gt; 'My\\V1\\Rest\\Track\\TrackHydrator',
              ),
              'My\\V1\\Rest\\Track\\TrackCollection' =&gt; array(
                  'entity_identifier_name' =&gt; 'id',
                  'route_name' =&gt; 'my.rest.track',
                  'route_identifier_name' =&gt; 'track_id',
                  'is_collection' =&gt; true,
              ),
          ),
      ),
  
      'zf-apigility' =&gt; array(
          'doctrine-connected' =&gt; array(
              'My\\V1\\Rest\\Track\\TrackResource' =&gt; array(
                  'object_manager' =&gt; 'doctrine.documentmanager.odm_default',
                  'hydrator' =&gt; 'My\\V1\\Rest\\Track\\TrackHydrator',
                  'query_providers' =&gt; array(
                      'update' =&gt; 'update',
                      'patch' =&gt; 'update',
                      'delete' =&gt; 'delete',
                  ),
              ),
          ),
      ),
  
      'doctrine-hydrator' =&gt; array(
          'My\\V1\\Rest\\Track\\TrackHydrator' =&gt; array(
              'entity_class' =&gt; 'My\\Entity\\Track',
              'object_manager' =&gt; 'doctrine.documentmanager.odm_default',
              'by_value' =&gt; true,
              'strategies' =&gt; array(
                  'track' =&gt; 'ZF\\Apigility\\Doctrine\\Server\\Hydrator\\Strategy\\CollectionExtract',
              ),
              'use_generated_hydrator' =&gt; true,
          ),
      ),
  );
  </code></pre>
  
  <p>Please, help. Thank you!</p>