diff --git a/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php b/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php index 3213b8670..39bb967e6 100644 --- a/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php +++ b/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php @@ -1206,7 +1206,7 @@ class BasicEntityPersister } else { throw ORMException::unrecognizedField($field); } - $conditionSql .= (is_array($value)) ? ' IN (?)' : ' = ?'; + $conditionSql .= (is_array($value)) ? ' IN (?)' : (($value === null) ? ' IS NULL' : ' = ?'); } return $conditionSql; } @@ -1291,6 +1291,10 @@ class BasicEntityPersister $params = $types = array(); foreach ($criteria AS $field => $value) { + if ($value === null) { + continue; // skip null values. + } + $type = null; if (isset($this->_class->fieldMappings[$field])) { $type = Type::getType($this->_class->fieldMappings[$field]['type'])->getBindingType(); diff --git a/tests/Doctrine/Tests/ORM/Functional/EntityRepositoryTest.php b/tests/Doctrine/Tests/ORM/Functional/EntityRepositoryTest.php index f344ff159..0e38fe209 100644 --- a/tests/Doctrine/Tests/ORM/Functional/EntityRepositoryTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/EntityRepositoryTest.php @@ -307,5 +307,18 @@ class EntityRepositoryTest extends \Doctrine\Tests\OrmFunctionalTestCase $repos->createNamedQuery('invalidNamedQuery'); } + + /** + * @group DDC-1087 + */ + public function testIsNullCriteria() + { + $repos = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser'); + $users = $repos->findBy(array('status' => null, 'username' => 'romanb')); + + $params = $this->_sqlLoggerStack->queries[$this->_sqlLoggerStack->currentQuery]['params']; + $this->assertEquals(1, count($params), "Should only execute with one parameter."); + $this->assertEquals(array('romanb'), $params); + } }