protected function applyConstraints(Builder $builder, array $constraints, $mode = Constraint::MODE_AND)
    {
        foreach ($constraints as $field => $constraint) {
            if (is_array($constraint)) {
                foreach ($constraint as $single_constraint) {
                    $this->applyConstraint($builder, $field, $single_constraint, $mode);
                }
            } else {
                $this->applyConstraint($builder, $field, $constraint, $mode);
            }
        }
    }