src/Zicht/Bundle/AdminBundle/Admin/TreeAdmin.php
public function createQuery($context = 'list')
    {
        if ($context === 'list') {
            /** @var $em \Doctrine\ORM\EntityManager */
            $em = $this->getModelManager()->getEntityManager($this->getClass());

            /** @var $cmd \Doctrine\Common\Persistence\Mapping\ClassMetadata */
            $cmd = $em->getMetadataFactory()->getMetadataFor($this->getClass());

            $queryBuilder = $em->createQueryBuilder();
            $queryBuilder
                ->select('n')
                ->from($this->getClass(), 'n');

            if ($cmd->hasField('root')) {
                $queryBuilder->orderBy('n.root, n.lft');
            } else {
                $queryBuilder->orderBy('n.lft');
            }

            return new ProxyQuery($queryBuilder);
        }
        return parent::createQuery($context);
    }
public function createQuery($context = 'list')
    {
        if ($context === 'list') {
            /** @var $em \Doctrine\ORM\EntityManager */
            $em = $this->getModelManager()->getEntityManager($this->getClass());

            /** @var $cmd \Doctrine\Common\Persistence\Mapping\ClassMetadata */
            $cmd = $em->getMetadataFactory()->getMetadataFor($this->getClass());

            $queryBuilder = $em->createQueryBuilder();
            $queryBuilder
                ->select('n')
                ->from($this->getClass(), 'n');

            if ($cmd->hasField('root')) {
                $queryBuilder->orderBy('n.root, n.lft');
            } else {
                $queryBuilder->orderBy('n.lft');
            }

            return new ProxyQuery($queryBuilder);
        }
        return parent::createQuery($context);
    }
public function createQuery ( $ context = 'list' ) { if ( $ context === 'list' ) { /** @var $em \Doctrine\ORM\EntityManager */ $ em = $ this -> getModelManager ( ) -> getEntityManager ( $ this -> getClass ( ) ) ; /** @var $cmd \Doctrine\Common\Persistence\Mapping\ClassMetadata */ $ cmd = $ em -> getMetadataFactory ( ) -> getMetadataFor ( $ this -> getClass ( ) ) ; $ queryBuilder = $ em -> createQueryBuilder ( ) ; $ queryBuilder -> select ( 'n' ) -> from ( $ this -> getClass ( ) , 'n' ) ; if ( $ cmd -> hasField ( 'root' ) ) { $ queryBuilder -> orderBy ( 'n.root, n.lft' ) ; } else { $ queryBuilder -> orderBy ( 'n.lft' ) ; } return new ProxyQuery ( $ queryBuilder ) ; } return parent :: createQuery ( $ context ) ; }
Override the default query builder to utilize correct sorting

@param string $context
@return ProxyQueryInterface
Override the default query builder to utilize correct sorting