# Parent.find(parent.id).to\_xml(:include =\> \[children, grandchildren\] = Help?

**URL:** <https://www.ruby-forum.com/t/parent-find-parent-id-to-xml-include-children-grandchildren-help/160474>\
**Category:** Rails\
**Created:** [February 16, 2009, 8:28pm UTC](https://www.ruby-forum.com/t/parent-find-parent-id-to-xml-include-children-grandchildren-help/160474 "2009-02-16T20:28:09Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![InventoryTrackers](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/59ef9b/32.png) [@InventoryTrackers](https://www.ruby-forum.com/u/InventoryTrackers)\
**Post date:** [February 16, 2009, 8:28pm UTC](https://www.ruby-forum.com/t/parent-find-parent-id-to-xml-include-children-grandchildren-help/160474/1 "2009-02-16T20:28:09Z")

</div>

I’ve read Fred Cheung’s excellent example of nested :includes at the  
link;

> **[Nested includes and joins - Space Vatican](https://www.spacevatican.org/2008/8/8/nested-includes-and-joins/)**
>
> Nested eager loads are a not entirely obvious bit of rails syntax. It’s not hard once you get it though. In a nutshell you have to tell …

His examples deal with including parent and children associations but  
I can’t see the connection of how to address a child, grandchild  
nested :include.

I am presenting my users’ with the ability to create a complex find  
upon the Parent table.  
The result of this find ( @parent ) will then be passed to another  
find whose purpose is to create a multilevel ‘nested’ array that is  
then passed to the .to\_xml method.

I am pursuing this approach in order to pass the resultant @xmlout  
array to the Jasper Reports ( iReport ) framework is which the user is  
able to generate some very robust reports.

Obviously, one might suggest this approach;

for parent in @parents  
@xmlout \<\< parent  
for child in parent.child  
@xmlout \<\< child  
for grandchild in child.grandchildren  
@xmlout \<\< grandchild

When this @xmlout is created the indention of the resulting XML file  
has the child and grandchild at equal levels in XML indentation as the  
parent.  
The only way I seem to be able to get a properly indented XML file  
that makes sense to the Jasper Reports framework is to call  
the .to\_xml method against a ‘ActiveRecord’ prepared nested array. The  
following attempts don’t ‘Blow Up’ but yield the child and NOT the  
grandchild nested array. These are;

@xmlout \<\< Parent.find(parent.id).to\_xml(:include =\> {:children =\>  
{:child =\> :grandchildren}})  
@xmlout \<\< Parent.find(parent.id).to\_xml(:include =\> {:children =\>  
{:grandchildren =\> :child}})

I am happy to share any parts of this endeavor which is loosely  
predicated upon the excellent “How to Integrate Jasper Reports” at  
[http://wiki.rubyonrails.org/rails/pages/howtointegratejasperreports](http://wiki.rubyonrails.org/rails/pages/howtointegratejasperreports)

Thank you,  
David
