o5snag
Last Updated: February 25, 2016
·
11.14K
· 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

3439

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

over 1 year ago ·