Description
The Valid
constraint default group is no Default
but null
.
If we defined something like:
class User
{
#[Assert\NotBlank(groups: ['create'])]
#[Assert\Length(min: 4, groups: ['create'])]
protected $firstName;
#[Assert\NotBlank(groups: ['create'])]
protected $lastName;
#[Assert\Valid]
private Collection $addresses;
}
class Address
{
#[Assert\NotBlank]
protected $street;
#[Assert\NotBlank]
#[Assert\Length(max: 5)]
protected $zipCode;
}
When we validate the User
with the create
validation groups, it also validate Address
, because the Valid
constraint define the validation groups to null
instead of Default
.
To have something that work as attended we must define Default
in Valid
constraint:
#[Assert\Valid(groups: ['Default'])]
private Collection $addresses;
}
It appear that this behavior is attended because there is a test to check that the Valid
default group is null
instead of Default
.
There is no info about that behavior in the documentation, and why this specific constraint do not have Default
as default group. I don't know why null
is the default value here, just pass some times to find why the behavior is not the attended one (expect Default
group like others).
Maybe @xabbuh you can help us about it (symfony/symfony#21111) ?