The reason you are getting those error messages is because you're failing type validation on one or more properties of the child entity. Review those constraints wherever you've defined them. In my case, this error was triggered when I assigned a "Type()" constraint on properties that were allowed to be NULL. Removing the type constraints eliminated the errors.
Regarding validation of child objects, this should only happen when you assign a "Valid" constraint on a property within the parent class, based on my reading of the documentation. However, it also appears to be controlled by the cascade_validation
field defined in the setDefaultOptions()
method of the related AbstractType
form type class, which you can also override by passing it in via the $options
array at the time you instantiate the form object:
$form = $this->createForm(
$formType,
$formModel,
array('cascade_validation' => false)
);
In your case, the cascade_validation
setting you've defined only applies to the properties of the Subscription child of your form object, where I think you're trying to apply the validation setting to the class itself (the class that has a Subscription object as one of its properties). So change you form builder instance to this:
$form = $this->createFormBuilder(null, array('cascade_validation' => false));
Alternatively, you can explicitly define the fields that you want validated within the controller as illustrated in the symfony2 documentation as follows:
use Symfony\Component\Validator\Constraints\Email;
public function addEmailAction($email)
{
$emailConstraint = new Email();
// all constraint "options" can be set this way
$emailConstraint->message = 'Invalid email address';
// use the validator to validate the value
$errorList = $this->get('validator')->validateValue(
$email,
$emailConstraint
);
if (count($errorList) == 0) {
// this IS a valid email address, do something
} else {
// this is *not* a valid email address
$errorMessage = $errorList[0]->getMessage();
// ... do something with the error
}
// ...
}