diff --git a/src/Bundle/ChillPersonBundle/Entity/Person/PersonResource.php b/src/Bundle/ChillPersonBundle/Entity/Person/PersonResource.php index 344f2103a..b6dc57ed8 100644 --- a/src/Bundle/ChillPersonBundle/Entity/Person/PersonResource.php +++ b/src/Bundle/ChillPersonBundle/Entity/Person/PersonResource.php @@ -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(); + } + } }