Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sonata Admin Bundle custom query for list to use existing Repository

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

like image 989
Vladimir Cvetic Avatar asked Mar 25 '14 11:03

Vladimir Cvetic


1 Answers

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;
    }
like image 110
jdharandas Avatar answered Oct 22 '22 07:10

jdharandas