Forum: Ruby on Rails Parent.find(parent.id).to_xml(:include => [children, grandchildren] = Help?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
E759aaf28892fcb753f96dd5be2c776e?d=identicon&s=25 InventoryTrackers (Guest)
on 2009-02-16 20:28
(Received via mailing list)
I've read Fred Cheung's excellent example of nested :includes at the
link;

http://www.spacevatican.org/2008/8/8/nested-includ...

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/howtointeg...

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