2

Well.. i have a simple Entity and tried to get all records from it:

    $em = $this->getDoctrine()->getManager();
    $news = $em->getRepository('AppBundle:Article')->findAll();
    var_dump($news); exit;

But it returns me very large response, check image bellow:

image

When i tried with this piece of code it returns me correct records in array, but why findAll doesn't work correct, it works for others entities?

    $news = $this->getDoctrine()
        ->getRepository('AppBundle:Article')
        ->createQueryBuilder('e')
        ->select('e')
        ->getQuery()
        ->getResult(\Doctrine\ORM\Query::HYDRATE_ARRAY);
  • 1
    Rather than `var_dump($news)` use Symfony dump : `dump($news)`. It will make your dump easier to read, for you and us as well. It might help you understand better why it's so "large"... ;) – Preciel May 29 '18 at 20:04
  • Hmm.. it returns me only one record (i have only one), so it is correct, but why when i use var_dump for other entities it returns me correct object.. probably this entity is the only one who have relations (manyToOne) with other enity .. xmm – Abdullah Javar May 29 '18 at 20:08
  • 1
    Most likely because here you're returning an object and not a simple array. Thus, there is a lot of data in the object beside the data of the entry. You can also dump in your twig view by doing `{{ dump() }}`. That last one can be with or without parameter. The more you will use the dump, the more you will understand them... ;) – Preciel May 29 '18 at 20:12
  • It's doing what the ORM does. You've identified the approach to get array hydrated result with Query Builder. Is what is is. – ficuscr May 29 '18 at 20:12
  • On a side note, for your second fragment of code, replace `getResult()` by `execute()` that way, it will also provide an object, which will be easier to manipulate... – Preciel May 29 '18 at 20:23
  • You could hydratate the query by default using getArrayResult() – Juan I. Morales Pestana May 29 '18 at 21:10
  • Could you please share very first lines of you `AppBundle\Article'` class? I mean the section with this lines of code `class Article {` and annotations above that – Peyman Mohamadpour May 30 '18 at 05:53
  • 1
    Possible duplicate of [Too much data with var\_dump in symfony2 doctrine2](https://stackoverflow.com/questions/11902099/too-much-data-with-var-dump-in-symfony2-doctrine2) – john Smith May 30 '18 at 07:20
  • Thank's to everyone :) – Abdullah Javar Jun 03 '18 at 15:48

0 Answers0