Skip to content

Commit ec7f84c

Browse files
committed
bug #17355 [DoctrineBridge][Validator] >= 2.3 Pass association instead of ID as argument (xavismeh)
This PR was squashed before being merged into the 2.3 branch (closes #17355). Discussion ---------- [DoctrineBridge][Validator] >= 2.3 Pass association instead of ID as argument | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - No verification on doctrine-orm version has been provided since the `composer.json` requires `"doctrine/orm": "~2.4,>=2.4.5"` and performing a query with an object as array argument has been added in 2.2.0-BETA1 (see https://github.com/doctrine/doctrine2/blob/2.2.0-BETA1/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php#L1511) Commits ------- 5c2d534 [DoctrineBridge][Validator] >= 2.3 Pass association instead of ID as argument
2 parents 76e3e65 + d129288 commit ec7f84c

File tree

2 files changed

+1
-36
lines changed

2 files changed

+1
-36
lines changed

Tests/Validator/Constraints/UniqueEntityValidatorTest.php

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
use Doctrine\Common\Persistence\ObjectManager;
1717
use Doctrine\Common\Persistence\ObjectRepository;
1818
use Symfony\Bridge\Doctrine\Test\DoctrineTestHelper;
19-
use Symfony\Bridge\Doctrine\Tests\Fixtures\CompositeIntIdEntity;
2019
use Symfony\Component\Validator\Tests\Constraints\AbstractConstraintValidatorTest;
2120
use Symfony\Bridge\Doctrine\Tests\Fixtures\SingleIntIdEntity;
2221
use Symfony\Bridge\Doctrine\Tests\Fixtures\DoubleNameEntity;
@@ -398,7 +397,7 @@ public function testAssociatedEntity()
398397

399398
$this->buildViolation('myMessage')
400399
->atPath('property.path.single')
401-
->setInvalidValue(1)
400+
->setInvalidValue($entity1)
402401
->assertRaised();
403402
}
404403

@@ -422,29 +421,6 @@ public function testAssociatedEntityWithNull()
422421
$this->assertNoViolation();
423422
}
424423

425-
/**
426-
* @expectedException \Symfony\Component\Validator\Exception\ConstraintDefinitionException
427-
* @expectedExceptionMessage Associated entities are not allowed to have more than one identifier field
428-
*/
429-
public function testAssociatedCompositeEntity()
430-
{
431-
$constraint = new UniqueEntity(array(
432-
'message' => 'myMessage',
433-
'fields' => array('composite'),
434-
'em' => self::EM_NAME,
435-
));
436-
437-
$composite = new CompositeIntIdEntity(1, 1, 'test');
438-
$associated = new AssociationEntity();
439-
$associated->composite = $composite;
440-
441-
$this->em->persist($composite);
442-
$this->em->persist($associated);
443-
$this->em->flush();
444-
445-
$this->validator->validate($associated, $constraint);
446-
}
447-
448424
/**
449425
* @expectedException \Symfony\Component\Validator\Exception\ConstraintDefinitionException
450426
* @expectedExceptionMessage Object manager "foo" does not exist.

Validator/Constraints/UniqueEntityValidator.php

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -92,17 +92,6 @@ public function validate($entity, Constraint $constraint)
9292
* getter methods in the Proxy are being bypassed.
9393
*/
9494
$em->initializeObject($criteria[$fieldName]);
95-
96-
$relatedClass = $em->getClassMetadata($class->getAssociationTargetClass($fieldName));
97-
$relatedId = $relatedClass->getIdentifierValues($criteria[$fieldName]);
98-
99-
if (count($relatedId) > 1) {
100-
throw new ConstraintDefinitionException(
101-
'Associated entities are not allowed to have more than one identifier field to be '.
102-
'part of a unique constraint in: '.$class->getName().'#'.$fieldName
103-
);
104-
}
105-
$criteria[$fieldName] = array_pop($relatedId);
10695
}
10796
}
10897

0 commit comments

Comments
 (0)