Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Valid Constraints multiple groups apply only on one #27257

Copy link
Copy link
Closed
@gregoirepaqueron

Description

@gregoirepaqueron
Issue body actions

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.