Last Updated: February 25, 2016
·
19.09K
· stefanosala

Add a HIDDEN select column to Doctrine query builder

Just add HIDDEN keyword to select:

<?php
namespace Acme\FooBundle\Repository;

use Doctrine\ORM\EntityRepository;

class FooRepository extends EntityRepository
{
    public function findRandom($number)
    {
        return $this->createQueryBuilder('q')
            ->select('q, RAND() as HIDDEN r')
            ->setMaxResults($number)
            ->orderBy('r')
            ->getQuery()
            ->execute();
    }
}

1 Response
Add your response

Yeah, I know RAND() is not the best way to select random rows :)

over 1 year ago ·