Description
Symfony version(s) affected: 3.4.8
I have a parent Entity with many childrens Entities. I have 2 groups of validations Default
and final
.
The goal is to use only the group Default
through a non-restrictive form, in order to valid the integrity of datum sent, then on the last page, display all the errors message more restrictive, with combining the 2 groups.
When i'm trying to validate on the 2 groups, i'm adding the 2 groups to Valid()
constraint, but only 1 is applied.
Exemple :
Mandate.php
/**
* @var Customer[]|Collection
* @Assert\Count(min="1", groups={"final"})
* @Assert\Valid(groups={"Default", "final"})
* @ORM\OneToMany(targetEntity="Customer", mappedBy="mandate", cascade={"persist", "remove"})
*/
protected $customers;
Customer.php
/**
* @var string
* @Assert\Length(max=80)
* @Assert\Email()
* @Assert\NotBlank(groups={"final"})
* @ORM\Column(type="string", nullable=true)
*/
protected $email;
/**
* @var string
* @Assert\Length(max=40)
* @Assert\NotBlank(groups={"final"})
* @ORM\Column(type="string", nullable=true)
*/
protected $firstName;
CustomerController.php
/**
* @param ValidatorInterface $validator
* @param Mandate $mandate
* @return \Symfony\Component\HttpFoundation\Response
*/
public function summaryAction(ValidatorInterface $validator, Mandate $mandate)
{
$errors = $validator->validate($mandate, null, ['Default', 'final']);
...
}
I forced in database that $firstName = null
and $email = "notvalidemail"
In the $errors
list, i will find only that the email is incorrect, but not that the firstname should be not null.
So, only the group Default
is applied.