def fold_references_helper(entity, array_of_refs, organization)
      ref = array_of_refs.shift
      field = entity[ref]
      return if field.blank?

      # Follow embedment path, remplace if it's not an array or a hash
      case field
      when Array
        field.each do |f|
          fold_references_helper(f, array_of_refs.dup, organization)
        end
      when Hash
        fold_references_helper(entity[ref], array_of_refs, organization)
      else
        id = field
        entity[ref] = [id_hash(id, organization)]
      end
    end
def fold_references_helper(entity, array_of_refs, organization)
      ref = array_of_refs.shift
      field = entity[ref]
      return if field.blank?

      # Follow embedment path, remplace if it's not an array or a hash
      case field
      when Array
        field.each do |f|
          fold_references_helper(f, array_of_refs.dup, organization)
        end
      when Hash
        fold_references_helper(entity[ref], array_of_refs, organization)
      else
        id = field
        entity[ref] = [id_hash(id, organization)]
      end
    end
Recursive method for folding references