Home > database >  One to many validation unique field with Symfony
One to many validation unique field with Symfony

Time:09-15

I have a Request entity with many Interventions like this :

Request.php

    /**
     * @ORM\OneToMany(targetEntity=Intervention::class, mappedBy="request")
     * @Assert\Count(min=1, max=3)
     * @Assert\Valid
     */
    private $interventions;

Interventions.php

     /**
     * @ORM\Column(type="date")
     * @Assert\NotBlank
     * @Assert\GreaterThanOrEqual("today  3 days")
     */
    private $idate;

    /**
     * @ORM\Column(type="smallint", options={"unsigned": true})
     * @Assert\Range(min=0, max=23)
     * @Assert\NotBlank
     */
    private $ifrom;

    /**
     * @ORM\Column(type="smallint", options={"unsigned": true})
     * @Assert\Range(min=0, max=23)
     * @Assert\NotBlank
     */
    private $ito;

I want to validate that in the case of multiple interventions that the idate is unique. How to do ?

I have see that for @Assert\Unique constraint : 6.1 The fields option was introduced in Symfony 6.1.. But i am using Symfony 5.4...

Thanks

CodePudding user response:

Solved with : How to validate unique entities in an entity collection in symfony2

And this one link : https://github.com/symfony/symfony/issues/25401

  • Related