$self->simplify_joins( \%simplifiedResult, $joinSpec, \%requiredSetOfRelations || undef);

Take all data in $joinSpec (which can be anything DBIC will accept, which includes hashes and arrays) and eliminate any relation not mentioned in \%requiredSetOfRelations. If %requiredSetOfRelations is undef, no relations are eliminated.

This function converts things like

[ { a => b },
  { a => { b => c } },
  a,
  a => [ d, f ],
]

into

{ a => { b => { c => {}, }, d => {}, f => {} } }

resulting in a minimum of joined tables.

This routine would be a little nicer if the output were

{ a => [ { b => c }, d, f ] }

but that would be a lot of work, and nothing to gain.

Note that for DBIC, regardless of nesting, the relations must each have unique names, which is why %requiredSetOfRelations is a one-level hash rather than a tree of hashes. However, the joins must be specified to DBIC as a tree.