Fix for null values in assosiated properties when using UniqueEntityValidator
This commit is contained in:
parent
dea0a7bba4
commit
8ddb74adaa
@ -343,6 +343,23 @@ class UniqueValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertEquals(1, $violationsList->count());
|
||||
}
|
||||
|
||||
public function testAssociatedEntityWithNull()
|
||||
{
|
||||
$entityManagerName = "foo";
|
||||
$em = DoctrineTestHelper::createTestEntityManager();
|
||||
$this->createSchema($em);
|
||||
$validator = $this->createValidator($entityManagerName, $em, 'Symfony\Bridge\Doctrine\Tests\Fixtures\AssociationEntity', array('single'), null, 'findBy', false);
|
||||
|
||||
$associated = new AssociationEntity();
|
||||
$associated->single = null;
|
||||
|
||||
$em->persist($associated);
|
||||
$em->flush();
|
||||
|
||||
$violationsList = $validator->validate($associated);
|
||||
$this->assertEquals(0, $violationsList->count());
|
||||
}
|
||||
|
||||
/**
|
||||
* @group GH-1635
|
||||
*/
|
||||
|
@ -89,7 +89,7 @@ class UniqueEntityValidator extends ConstraintValidator
|
||||
return;
|
||||
}
|
||||
|
||||
if ($class->hasAssociation($fieldName)) {
|
||||
if (null !== $criteria[$fieldName] && $class->hasAssociation($fieldName)) {
|
||||
/* Ensure the Proxy is initialized before using reflection to
|
||||
* read its identifiers. This is necessary because the wrapped
|
||||
* getter methods in the Proxy are being bypassed.
|
||||
|
Reference in New Issue
Block a user