title: symfony doctrine QueryBuilder to array result
body: <p>I want to get array from doctrine query. 
  I've self-referencing entity</p>
  
  <p><strong>App\Entity\AccessModule</strong></p>
  
  <pre><code>/**
   * @ORM\ManyToOne(targetEntity="App\Entity\AccessModule", inversedBy="children")
   * @ORM\JoinColumn(name="parent_id", referencedColumnName="id", nullable=true)
   */
  private $parent;
  
  /**
   * @ORM\OneToMany(targetEntity="App\Entity\AccessModule", mappedBy="parent", fetch="EAGER")
   * @Serializer\MaxDepth(2)
   */
  private $children;
  
  
  /**
   * AccessModule constructor.
   */
  public function __construct()
  {
      $this-&gt;children = new ArrayCollection();
  }
  </code></pre>
  
  <p>In this repository</p>
  
  <p><strong>App\Entity\AccessModuleRepository</strong></p>
  
  <pre><code> public function findAllArray()
  {
      return $this-&gt;createQueryBuilder('a')
          -&gt;getQuery()
          -&gt;getResult();
  }
  </code></pre>
  
  <p>this return colection of objects with children and parent. But when I want to get this query as array <code>-&gt;getArrayResult()</code> I get array only with "id" and "name" without subarry "children" and "parent".</p>
  
  <p><strong>return $this->createQueryBuilder('a')->getQuery()->getArrayResult();</strong></p>
  
  <pre><code>array:3 [▼
   0 =&gt; array:2 [▼
     "id" =&gt; 2
     "name" =&gt; "Common module"
    ]
    1 =&gt; array:2 [▼
      "id" =&gt; 3
      "name" =&gt; "User Module"
   ]
   2 =&gt; array:2 [▼
      "id" =&gt; 4
      "name" =&gt; "Admin Module"
    ]
  ]
  </code></pre>
  
  <p><strong>return $this->createQueryBuilder('a')->getQuery()->getResult();</strong></p>
  
  <pre><code>  array:3 [▼
    0 =&gt; AccessModule {#5118 ▼
      -id: 2
      -name: "Common module"
      -parent: null
      -children: PersistentCollection {#5208 ▼
        -snapshot: array:2 [ …2]
        -owner: AccessModule {#5118}
        -association: array:15 [ …15]
        -em: EntityManager {#2624 …11}
        -backRefFieldName: "parent"
        -typeClass: ClassMetadata {#3093 …}
        -isDirty: false
        #collection: ArrayCollection {#5209 ▼
          -elements: array:2 [▼
            0 =&gt; AccessModule {#5325 ▼
              -id: 3
              -name: "User Module"
              -parent: AccessModule {#5118}
              -children: PersistentCollection {#5327 ▶}
            }
            1 =&gt; AccessModule {#5328 ▼
              -id: 4
              -name: "Admin Module"
              -parent: AccessModule {#5118}
              -children: PersistentCollection {#5330 ▶}
            }
          ]
        }
        #initialized: true
      }
    }
    1 =&gt; AccessModule {#5325 ▶}
    2 =&gt; AccessModule {#5328 ▶}
  ]
  </code></pre>
  
  <p>How to get array from getResult() with referncing objects?</p>
  
  <p><strong>Expected result</strong></p>
  
  <pre><code>[
   [0] =&gt; [
      'id' =&gt; 1,
      'name' =&gt; 'Common Module',
      'parent' =&gt; null,
      'children =&gt; [
          [0] =&gt; [
              'id' =&gt; 2,
              'name' =&gt; 'User Module',
              'parent' =&gt; 1,
              'children' =&gt; []
              ],
          [1] =&gt; [
              'id' =&gt; 3,
              'name' =&gt; 'Admin Module',
              'parent' =&gt; 1,
              'children' =&gt; []
              ]
          ]
      ],
   [1] =&gt; [
      'id' =&gt; 2,
      'name' =&gt; 'User Module',
      'parent' =&gt; 1,
      'children' =&gt; []
      ],
   [2] =&gt; [
      'id' =&gt; 3,
      'name' =&gt; 'Admin Module',
      'parent' =&gt; 1,
      'children' =&gt; []
      ]
  ]
  </code></pre>