6

I have my admin class creating a custom list using createQuery method

public function createQuery($context = 'list')
{
    $query = parent::createQuery($context);
    $query->andWhere(
        ....
    );
    ....
    return $query;
}

It all works just fine, but since I have repository with this query already defined and tests already written for that repository I was wondering if it was possible to utilize doctrine repository method instead of this?

Thanks

Vladimir Cvetic
  • 832
  • 3
  • 8
  • 23
  • https://sonata-project.org/bundles/admin/master/doc/reference/action_list.html#customizing-the-query-used-to-generate-the-list – breq Jul 08 '15 at 10:30

1 Answers1

17

Of course you can, as far as you return a Sonata\DoctrineORMAdminBundle\Datagrid\ProxyQuery instance :

   /**
     * {@inheritDoc}
     */
    public function createQuery($context = 'list')
    {
        $repository = $this->modelManager->getEntityManager($this->getClass())->getRepository($this->getClass());
        $query = new ProxyQuery($repository->createMyCustomQueryBuilder());

        foreach ($this->extensions as $extension) {
            $extension->configureQuery($this, $query, $context);
        }

        return $query;
    }
jdharandas
  • 416
  • 4
  • 7
  • 1
    here is more about it: https://sonata-project.org/bundles/admin/master/doc/reference/action_list.html#customizing-the-query-used-to-generate-the-list – breq Jul 08 '15 at 10:30
  • Link is dead: new link https://docs.sonata-project.org/projects/SonataAdminBundle/en/3.x/reference/action_list/#customizing-the-query-used-to-generate-the-list – Tofandel Aug 14 '23 at 08:42