class Athena::Validator::Constraints::Valid
inherits Athena::Validator::Constraint
#
Tells the validator that it should also validate objects embedded as properties on an object being validated.
Configuration#
Optional Arguments#
Note
This constraint does not support a message
argument.
groups#
Type: Array(String) | String | Nil
Default: nil
The validation groups this constraint belongs to.
AVD::Constraint::DEFAULT_GROUP
is assumed if nil
.
payload#
Type: Hash(String, String)?
Default: nil
Any arbitrary domain-specific data that should be stored with this constraint.
The payload is not used by Athena::Validator
, but its processing is completely up to you.
Usage#
Without this constraint, objects embedded in another object are not valided.
class SubObjectOne
include AVD::Validatable
@[Assert::NotBlank]
getter string : String = ""
end
class SubObjectTwo
include AVD::Validatable
@[Assert::NotBlank]
getter string : String = ""
end
class MyObject
include AVD::Validatable
# This object is not validated when validating `MyObject`.
getter sub_object_one : SubObjectOne = SubObjectOne.new
# Have the validator also validate `SubObjectTwo` when validating `MyObject`.
@[Assert::Valid]
getter sub_object_two : SubObjectTwo = SubObjectTwo.new
end
Constructors#
.new(traverse : Bool = true, groups : Array(String) | String | Nil = nil, payload : Hash(String, String) | Nil = nil)
#
Methods#
#validated_by : AVD::ConstraintValidator.class
#
Returns the AVD::ConstraintValidator.class
that should handle validating self
.