allow the deletion of a relationship

This commit is contained in:
Julie Lenaerts 2022-07-18 12:00:09 +02:00
parent 85796c2271
commit 88961e3e7e

View File

@ -39,6 +39,7 @@ class RelationshipNoDuplicateValidator extends ConstraintValidator
$fromPerson = $value->getFromPerson();
$toPerson = $value->getToPerson();
$relationType = $value->getRelation();
$relationships = $this->relationshipRepository->findBy([
'fromPerson' => [$fromPerson, $toPerson],
@ -46,11 +47,11 @@ class RelationshipNoDuplicateValidator extends ConstraintValidator
]);
foreach ($relationships as $r) {
if (
$r->getFromPerson() === $fromPerson
if ($r->getRelation()->getId() !== $relationType->getId() &&
($r->getFromPerson() === $fromPerson
|| $r->getFromPerson() === $toPerson
|| $r->getToPerson() === $fromPerson
|| $r->getToPerson() === $toPerson
|| $r->getToPerson() === $toPerson)
) {
$this->context->buildViolation($constraint->message)
->addViolation();