violation added if all three association entities are null

This commit is contained in:
Julie Lenaerts 2022-01-26 11:20:47 +01:00
parent f27dca6fb5
commit 51ab013bd7

View File

@ -22,6 +22,8 @@ use DateTimeInterface;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\DiscriminatorMap;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
/**
* @ORM\Entity
@ -256,4 +258,16 @@ class PersonResource implements TrackCreationInterface, TrackUpdateInterface
return $this;
}
/**
* @Assert\Callback
*/
public function validate(ExecutionContextInterface $context, $payload)
{
if ($this->person === null && $this->thirdParty === null && $this->freeText === null ) {
$context->buildViolation('You must associate at least one entity')
->atPath('person')
->addViolation();
}
}
}