title: Apigility Doctrine filter all fetch
body: <p>I'm on an ZF2 Apigility application with doctrine and <strong><a href="https://github.com/zfcampus/zf-doctrine-querybuilder" rel="nofollow">the QueryBuilderFilter module</a></strong>.</p>
  
  <p>Based on <strong><a href="http://tomhanderson.blogspot.fr/2014/12/applying-doctrine-querybuilder-filters.html" rel="nofollow">this example</a></strong></p>
  
  <p>I am trying to add a filter to all entities fetch that contain an <code>IdDealer</code> property.
  For that I have attached a <code>FetchListener</code> to all fetch events :</p>
  
  <pre><code>DoctrineResourceEvent::EVENT_FETCH_PRE
  DoctrineResourceEvent::EVENT_FETCH_ALL_PRE
  </code></pre>
  
  <p>And then I try to add a filter to the query if the entity is compatible with this filter.</p>
  
  <pre><code>public function __invoke(DoctrineResourceEvent $event)
  {
      if ($event-&gt;getName() == DoctrineResourceEvent::EVENT_FETCH_ALL_PRE)
          $entity_class = $event-&gt;getEntity();
      else //DoctrineResourceEvent::EVENT_FETCH_PRE
          $entity_class = $event-&gt;getEntityClassName();
  
  
      /** Entity has idDealer so we filter for the user */
      if (method_exists($entity_class, 'getIdDealer')) {
          $em = $event-&gt;getObjectManager();
          $filterManager = $this-&gt;getServiceManager()-&gt;get('Zf\Doctrine\QueryBuilder\Filter\ManagerOrm');
          $filterManager-&gt;filter(
              $em-&gt;createQueryBuilder()-&gt;select('row')-&gt;from($entity_class, 'row'),
              $em-&gt;getMetadataFactory()-&gt;getMetadataFor($entity_class),
              [
                  'filter' =&gt; [
                      'type' =&gt; 'eq',
                      'field' =&gt; 'idDealer',
                      'value' =&gt; (int)$this-&gt;getUser()-&gt;getIdDealer()-&gt;getId(),
                  ]
              ]
          );
      }
  }
  </code></pre>
  
  <p>But I cannot get the filter to work.
  I have found some info on internet that says that I should be able to retrieve the <code>QueryBuilder</code> from the event but it doesn't seem to be the case anymore.</p>
  
  <p>Anyone with an idea on how to get this working ?</p>