Combining min_size? and each


#1

Hi All,

I’m attempting to make a validation that checks an array is a certain size, and also the contents of the array is correct.

For example:

Dry::Validation.Schema do
  required(:people).filled(min_size?: 10).each do
    required(:name) { filled? & str? }
  end
end

I’ve tried a number of different ways of specifying this. However, I can only ever get either min_size to report an error (and when correctly sized does not report an error for a missing name - or have the minimum size ignored, but the name rule obeyed.

What’s the proper way to do this?

Thanks,

Theo


#2

Something like this should work:

Dry::Validation.Schema do
  required(:people).value(:array?, min_size?: 10) do
    each do
      schema do
        required(:name).filled(:str?)
      end
    end
  end
end

Hope this helps.