InventoryTrackers
2009-Feb-16 19:13 UTC
Parent.find(parent.id).to_xml(:include => [children, grandchildren] = Help?
I''ve read Fred Cheung''s excellent example of nested :includes at the link; http://www.spacevatican.org/2008/8/8/nested-includes-and-joins 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 Thank you, David --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---