Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork5.2k
Description
There is currently little to no prose documentation about validating associations (apart from theValid
reference docs), both in the Validator documentation and in the Form documentation.
The Validator documentation should mention that cascaded validation needs to be activated actively for the associations of an object:
Annotations:
/** * @Assert\Valid */private$author;
YAML:
properties:author: -Valid:~
XML:
<propertyname="author"> <constraintname="Valid" /></property>
When applied to traversable relations (i.e. an array or a collection object), the relation will be traversed by default. Each object in the collection will be validated as well. This can be deactivated by setting the "traverse" option tofalse
.
Deep traversal (e.g. in multi-level arrays) can be enabled by setting the "deep" option totrue
.
If you don't want to constrain a relationship with "Valid", but still validate the related object in the Form component, you can set the "cascade_validation" option to true on the root form:
$resolver->setDefaults(array('cascade_validation' =>true,));
Constraints set using the "constraints" option willalways be validated for nested forms, regardless of the "cascade_validation" setting.