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();
}
}
Written by Stefano Sala
Related protips
1 Response
Yeah, I know RAND() is not the best way to select random rows :)
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Symfony
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#