# Validations only run with certain option requirements

**URL:** <https://discourse.dry-rb.org/t/validations-only-run-with-certain-option-requirements/1459>\
**Category:** dry-validation\
**Created:** [April 29, 2022, 10:16pm UTC](https://discourse.dry-rb.org/t/validations-only-run-with-certain-option-requirements/1459 "2022-04-29T22:16:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![state-developer](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.dry-rb.org/state-developer/32/763_2.png) [@state-developer](https://discourse.dry-rb.org/u/state-developer)\
**Post date:** [April 29, 2022, 10:16pm UTC](https://discourse.dry-rb.org/t/validations-only-run-with-certain-option-requirements/1459/1 "2022-04-29T22:16:03Z")

</div>

I have a Contract that has the following setup:

```auto
class MyContract < Dry::Validation::Contract
  option :some_activerecord

  params do
     optional(:amount).maybe(:number?, gt?: 0)
  end

  rule do
    binding.pry
  end
end

```

Is there a way to only have the optional `param` validation to run if a certain property in `some_activerecord` model is equal to a value without having to create an actual rule? Trying to keep the params as short as possible, and wondering if this is possible?

I’ve tried:

`optional(:amount).maybe(:number?, gt?: 0) { some_activerecord.value == 0 }`

But this failed with `undefined local variable or method`.

Thanks!

---

<div class="post-metadata">

**Author:** ![bkuhlmann](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.dry-rb.org/bkuhlmann/32/557_2.png) [@bkuhlmann](https://discourse.dry-rb.org/u/bkuhlmann)\
**Post date:** [May 3, 2022, 12:17am UTC](https://discourse.dry-rb.org/t/validations-only-run-with-certain-option-requirements/1459/2 "2022-05-03T00:17:46Z")

</div>

Yeah, what you want to do is look at how custom types are supported in [Dry Schema](https://dry-rb.org/gems/dry-schema). Specifically:

- [Basic](https://dry-rb.org/gems/dry-schema/1.9/basics/type-specs)
- [Advanced](https://dry-rb.org/gems/dry-schema/1.9/advanced/custom-types)

Depending on your needs, you could define all of this within a schema and then reference that schema withing your contract (validator) or you could just use your custom type directly within your validator as [documented](https://dry-rb.org/gems/dry-validation/1.8/schemas/#using-custom-types) in the Dry Validation documentation.
