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
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;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With