Doctrine query result

I am developing an application using Symfony2 and Doctrine2. I also use Doctrine 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 the result that I would get in $ Emaitza to look. It would be something like:

$ Emaitza [0] ['Gordailua'] = The first value of Gordailua is selected.

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

I was a little confused. Thank.

+3
source share
2 answers

First of all, you need to specify the From clause:

$qb->from('YourBundle\Entity\ParentOfGordailua as pg');

You can use: getArrayResult () to retrieve the data as an array, if you want to get the first object from Object ArrayCollection (when you use getResult (), you should:

$Gordailua = $Emaitza->first()->getGordailua();

exaples: http://docs.doctrine-project.org/projects/doctrine-orm/en/2.0.x/reference/dql-doctrine-query-language.html

-1

, , , .. ..

, , .. , ,

$qb->setMaxResults(1)

,

$single_result = $qb->getSingleResult()

,

$qb->getQuery()->setMaxResults(1)->getSingleResult();
+9

All Articles