Closed
Description
I have an entity where I'm using the following validators:
/**
* @Assert\Callback(methods={"isValid"}, groups={"group1", "group2"})
*/
class UserProduct
{
/**
* @var string $title
* @Assert\NotBlank(message="title.blank", groups={"group1", "group2"});
*/
private $title;
/**
* @var Project\AuthenticationBundle\Entity\User
* @Assert\Valid(groups={"group2"});
*/
private $user;
Calling $this->get('validator')->validate($userProduct, array('group1'))
asserts the class constraint (@Assert\Callback
) and the $title
property but also the $user
one too, even though it's not included in the validation group. The same happens if no groups are passed to the Valid
constraint.
Removing the @Assert\Valid()
constraint and running the same validation again for group1
does not assert the $user
property, as expected.
The MemberMetadata
class appears to always force the cascading of the Valid
constraint, although I'm unsure if this is exactly related to the issue I'm experiencing.
// Symfony\Component\Validator\Mapping\MemberMetadata.php
if ($constraint instanceof Valid) {
$this->cascaded = true;
$this->collectionCascaded = $constraint->traverse;
} else {
parent::addConstraint($constraint);
}
Running on Symfony2 master.