title: ArangoDB AQL Query - merge children into parent
body: <p>I have a simple parent-child relationship in ArangoDB.  Each parent document can have zero to many children.  Let's say the parent document has attributes pa1, and the child docs have one attribute ca1, and a reference back to the parent _id of "_id_parent".  How do I write an AQL query to return a result set like:</p>
  
  <pre><code>    [{
              "_key": "111",
              "_id": "parent/111",
              "pa1": "aaa",
              "children": [{
                      "_key": "21",
                      "_id": "child/21",
                      "_id_parent": "parent/111",
                      "ca1": "www"
                  },
                  {
                      "_key": "22",
                      "_id": "child/22",
                      "_id_parent": "parent/111",
                      "ca1": "xxx"
                  }
              ]
          },
          {
              "_key": "222",
              "_id": "parent/222",
              "pa1": "ddd",
              "children": [{
                      "_key": "31",
                      "_id": "child/31",
                      "_id_parent": "parent/222",
                      "ca1": "yyy"
                  },
                  {
                      "_key": "32",
                      "_id": "child/32",
                      "_id_parent": "parent/222",
                      "ca1": "zzz"
                  }
              ]
          }
      ]
  </code></pre>
  
  <p>In other words, how do I "flatten" this:</p>
  
  <pre><code>    FOR p IN Parent
      FILTER p.pa1 == @parm1
      LET children = (
          (FOR c IN Child
              FILTER c._id_parent == p._id
              RETURN c)
      )
      RETURN {p, children}
  </code></pre>