1
0
mirror of synced 2024-12-13 22:56:04 +03:00

[DDC-1087] Add missing resolution to IS NULL in EntityRepository when passing a null value as a criteria.

This commit is contained in:
Benjamin Eberlei 2011-04-03 09:03:43 +02:00
parent db82ef3e61
commit a329007526
2 changed files with 18 additions and 1 deletions

View File

@ -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();

View File

@ -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);
}
}