Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select distinct results using findAll in doctrine

Can I select distinct value using findAll() function?

I'm trying :

$province = $em->getRepository("FrontendBundle:Store")->findAll(array('distinct' => true));

But it doesn't seems to work.

like image 479
Isky Avatar asked Nov 25 '15 13:11

Isky


1 Answers

The findall don't support this behaviour, in order to make a query on-the-fly (better in a separate repository class) you can do as follow:

/** @var  $qb  \Doctrine\ORM\QueryBuilder*/
$qb = $em->getRepository("GerlaFrontendBundle:Store")->createQueryBuilder("p");

$province = $qb->select("p")
    ->distinct(true)
    ->getQuery()
    ->getResult();

Hope this help

like image 191
Matteo Avatar answered Oct 11 '22 22:10

Matteo