diff --git a/lib/Doctrine/ORM/Persisters/SqlExpressionVisitor.php b/lib/Doctrine/ORM/Persisters/SqlExpressionVisitor.php index b06358a20..7736943c6 100644 --- a/lib/Doctrine/ORM/Persisters/SqlExpressionVisitor.php +++ b/lib/Doctrine/ORM/Persisters/SqlExpressionVisitor.php @@ -66,6 +66,7 @@ class SqlExpressionVisitor extends ExpressionVisitor $value = $comparison->getValue()->getValue(); // shortcut for walkValue() if (isset($this->classMetadata->associationMappings[$field]) && + $value !== null && ! is_object($value) && ! in_array($comparison->getOperator(), array(Comparison::IN, Comparison::NIN))) { diff --git a/tests/Doctrine/Tests/ORM/Functional/EntityRepositoryTest.php b/tests/Doctrine/Tests/ORM/Functional/EntityRepositoryTest.php index 517ff3d97..6432c3072 100644 --- a/tests/Doctrine/Tests/ORM/Functional/EntityRepositoryTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/EntityRepositoryTest.php @@ -842,6 +842,35 @@ class EntityRepositoryTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->assertEquals(2, count($users)); } + /** + * @group DDC-2478 + */ + public function testMatchingCriteriaNullAssocComparison() + { + $fixtures = $this->loadFixtureUserEmail(); + $user = $this->_em->merge($fixtures[0]); + $repository = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser'); + $criteriaIsNull = Criteria::create()->where(Criteria::expr()->isNull('email')); + $criteriaEqNull = Criteria::create()->where(Criteria::expr()->eq('email', null)); + + $user->setEmail(null); + $this->_em->persist($user); + $this->_em->flush(); + $this->_em->clear(); + + $usersIsNull = $repository->matching($criteriaIsNull); + $usersEqNull = $repository->matching($criteriaEqNull); + + $this->assertCount(1, $usersIsNull); + $this->assertCount(1, $usersEqNull); + + $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $usersIsNull[0]); + $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $usersEqNull[0]); + + $this->assertNull($usersIsNull[0]->getEmail()); + $this->assertNull($usersEqNull[0]->getEmail()); + } + /** * @group DDC-2055 */