Isky Isky - 7 months ago 110
PHP Question

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.

Answer

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

Comments