Forum: Ruby on Rails Parent.find( => [children, grandchildren] = Help?

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
InventoryTrackers (Guest)
on 2009-02-16 21:28
(Received via mailing list)
I've read Fred Cheung's excellent example of nested :includes at the

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
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( => {:children =>
{:child => :grandchildren}})
@xmlout << Parent.find( => {: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

Thank you,
This topic is locked and can not be replied to.