How to validate that array contains instances of ActiveRecord class?

For keys of a single value something like required(:user).value(type?: User) works great, but what if users is an array? I’ve tried required(:users).each(type?: User) and it’s equivalent block syntax to try and mimic the pattern on the docs (required(:ids).each(:int?)) but that results in:

NoMethodError: undefined method 'map' for nil:NilClass at the contract call site.

I’m sure I’m missing something obvious but I can’t seem to figure it out.

This should work:

dry-validation> c=contract { schema { required(:strings).value(:array?).each(type?: String) } }
=> #<#<Class:0x00007f877b908be8> schema=#<Dry::Schema::Processor keys=[:strings] rules={:strings=>"key?(:strings) AND key[strings](array? AND each(type?(String)))"}> rules=[]>
dry-validation> c.(strings: ["foo", :bar]).errors.to_h
=> {:strings=>{1=>["must be String"]}}

…but I don’t recommend writing contracts that check if values are AR objects. dry-validation/schema are meant to be used to validate data structures. Checking types like that is against duck typing.