Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Doctrine querybuilder result

I am developing an application using Symfony2 and Doctrine2. I also use Doctrine's QueryBuilder. I have this query:

public function getInterpDesberdinak($MarkId)
    {
          $qb = $this->createQueryBuilder('c')
              ->select('DISTINCT c.Gordailua, c')
              ->where('c.MarkIdGordailua = :MarkId')
              ->setParameter('MarkId', $MarkId);
          $Emaitza = $qb->getQuery()->getResult();
          return $Emaitza;
    }       

I would like to how the result would I get in $Emaitza would look. Would it be something like:

$Emaitza[0]['Gordailua'] = the first Gordailua value selected.

and then $Emaitza[0][?????] = The first c type object.

I am kind of confused.Thanks.

like image 608
Haritz Avatar asked Jan 17 '23 15:01

Haritz


1 Answers

Can't remember how I came to this post, but I even read it and thought, well .. anyways ..

I think he's asking to get the first result, if so .. the query should first know what the maximum size of result is by doing

$qb->setMaxResults(1)

and then you can call a method that really defines itself

$single_result = $qb->getSingleResult()

So in the example given the code will look like

$qb->getQuery()->setMaxResults(1)->getSingleResult();
like image 163
dbf Avatar answered Jan 25 '23 14:01

dbf