Duplicate a list of things with a list of things

Hi,

I’m building a quoting app for internal use at our company and the last major hurdle I’m facing is how to increment a quote version. Quotes are structured as follows;

  • [Quote] contains a list of [Section]s
  • [Section] contains a [Quote] and a list of [Line Item]s
  • [Line Item] contains a [Section]

I want to create a copy of a quote, including all its sections and line items, then increment its version number. I get as far as copying a list of things for the line items and sections but can’t figure out how to assign the correct new line items to the correct new sections.

Any help would be greatly appreciated.

Jack