def filter_connec_entity_for_id_refs_helper(entity_hash, tree)
      return if tree.empty?

      entity_hash.slice!(*tree.keys)

      tree.each do |key, children|
        case entity_hash[key]
        when Array
          entity_hash[key].each do |hash|
            filter_connec_entity_for_id_refs_helper(hash, children)
          end
        when Hash
          filter_connec_entity_for_id_refs_helper(entity_hash[key], children)
        end
      end
    end
def filter_connec_entity_for_id_refs_helper(entity_hash, tree)
      return if tree.empty?

      entity_hash.slice!(*tree.keys)

      tree.each do |key, children|
        case entity_hash[key]
        when Array
          entity_hash[key].each do |hash|
            filter_connec_entity_for_id_refs_helper(hash, children)
          end
        when Hash
          filter_connec_entity_for_id_refs_helper(entity_hash[key], children)
        end
      end
    end
Recursive method for filtering connec entities