From 4f70e9fe5a2b87607bbd37c4bdb2679c3434468a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20B=C3=B6hmer?= Date: Sun, 17 May 2020 20:58:58 +0200 Subject: [PATCH] Only retrieve parts, when partLot has already an ID. Fixes issue #59. --- src/Validator/Constraints/ValidPartLotValidator.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Validator/Constraints/ValidPartLotValidator.php b/src/Validator/Constraints/ValidPartLotValidator.php index e89b004c..bd00c9f0 100644 --- a/src/Validator/Constraints/ValidPartLotValidator.php +++ b/src/Validator/Constraints/ValidPartLotValidator.php @@ -44,6 +44,7 @@ namespace App\Validator\Constraints; use App\Entity\Parts\PartLot; use App\Entity\Parts\Storelocation; +use Doctrine\Common\Collections\ArrayCollection; use Doctrine\ORM\EntityManagerInterface; use Symfony\Component\Form\Exception\UnexpectedTypeException; use Symfony\Component\Validator\Constraint; @@ -77,7 +78,12 @@ class ValidPartLotValidator extends ConstraintValidator //We can only validate the values if we know the storelocation if ($value->getStorageLocation()) { $repo = $this->em->getRepository(Storelocation::class); - $parts = $repo->getParts($value); + //We can only determine associated parts, if the part have an ID + if ($value->getID() !== null) { + $parts = new ArrayCollection($repo->getParts($value)); + } else { + $parts = new ArrayCollection([]); + } //Check for isFull() attribute if ($value->getStorageLocation()->isFull()) {