# Using \`filled?\` with \`each\`

**URL:** <https://discourse.dry-rb.org/t/using-filled-with-each/386>\
**Category:** dry-validation\
**Created:** [November 2, 2017, 1:56am UTC](https://discourse.dry-rb.org/t/using-filled-with-each/386 "2017-11-02T01:56:14Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![twe4ked](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.dry-rb.org/twe4ked/32/154_2.png) [@twe4ked](https://discourse.dry-rb.org/u/twe4ked)\
**Post date:** [November 2, 2017, 1:56am UTC](https://discourse.dry-rb.org/t/using-filled-with-each/386/1 "2017-11-02T01:56:14Z")

</div>

I can’t seem to get `filled` to work with `each`. I’m not sure if this should be supported or I’m doing it the wrong way.

Example:

```ruby
require 'dry-validation'

schema = Dry::Validation.Schema do
  required(:foo).filled(:array?).each do
    schema do
      required(:bar).filled(:str?)
    end
  end
end

# 1.
p schema.({}).errors
# => {:foo=>["is missing"]}

# 2.
p schema.(foo: []).errors
# => {:foo=>["must be filled"]}

# 3.
p schema.(foo: [1]).errors
# => {}

# 4.
p schema.(foo: [{}]).errors
# => {}

# 5.
p schema.(foo: [{bar: 'baz'}]).errors
# => {}

```

With the above example I would expect 3. and 4. to return errors related to the internal `schema`. If I remove the `filled(:array?)` from the schema the internal schema validates as expected.

Cheers

---

<div class="post-metadata">

**Author:** ![solnic](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.dry-rb.org/solnic/32/779_2.png) [@solnic](https://discourse.dry-rb.org/u/solnic)\
**Post date:** [November 2, 2017, 2:36am UTC](https://discourse.dry-rb.org/t/using-filled-with-each/386/2 "2017-11-02T02:36:24Z")

</div>

This is a known limitation, chaining is not suported, so you need:

```ruby
schema = Dry::Validation.Schema do
  required(:foo).value(:array?, :filled?) do
    each do
      schema do
        required(:bar).filled(:str?)
      end
    end
  end
end

```

---

<div class="post-metadata">

**Author:** ![twe4ked](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.dry-rb.org/twe4ked/32/154_2.png) [@twe4ked](https://discourse.dry-rb.org/u/twe4ked)\
**Post date:** [November 14, 2017, 3:45pm UTC](https://discourse.dry-rb.org/t/using-filled-with-each/386/3 "2017-11-14T15:45:25Z")

</div>

Awesome, thanks @solnic.

---

<div class="post-metadata">

**Author:** ![izorsa](https://avatars.discourse-cdn.com/v4/letter/i/c37758/32.png) [@izorsa](https://discourse.dry-rb.org/u/izorsa)\
**Post date:** [December 6, 2018, 6:42pm UTC](https://discourse.dry-rb.org/t/using-filled-with-each/386/4 "2018-12-06T18:42:42Z")

</div>

@solnic Hi! Is it possible to run the loop only when the array is filled?

```
schema = Dry::Validation.Schema do
  required(:foo).maybe(:array?) do
    each do
      schema do
        required(:bar).filled(:str?)
      end
    end
  end
end
```
