def merge_id_hashes_helper(hash, array_of_refs, src, path = [])
      ref = array_of_refs.shift
      field = hash[ref]

      if array_of_refs.empty? && field
        value = value_from_hash(src, path + [ref])
        if value.is_a?(Array)
          hash[ref] = (field + value).uniq
        else
          hash.delete(ref)
        end
      else
        case field
        when Array
          field.each_with_index do |f, index|
            merge_id_hashes_helper(f, array_of_refs.dup, src, path + [ref, index])
          end
        when Hash
          merge_id_hashes_helper(field, array_of_refs, src, path + [ref])
        end
      end
    end
def merge_id_hashes_helper(hash, array_of_refs, src, path = [])
      ref = array_of_refs.shift
      field = hash[ref]

      if array_of_refs.empty? && field
        value = value_from_hash(src, path + [ref])
        if value.is_a?(Array)
          hash[ref] = (field + value).uniq
        else
          hash.delete(ref)
        end
      else
        case field
        when Array
          field.each_with_index do |f, index|
            merge_id_hashes_helper(f, array_of_refs.dup, src, path + [ref, index])
          end
        when Hash
          merge_id_hashes_helper(field, array_of_refs, src, path + [ref])
        end
      end
    end
Recursive helper for merging id hashes