diff --git a/lib/Doctrine/ORM/Query/Expr/Base.php b/lib/Doctrine/ORM/Query/Expr/Base.php index 28771890c..6eac70a27 100644 --- a/lib/Doctrine/ORM/Query/Expr/Base.php +++ b/lib/Doctrine/ORM/Query/Expr/Base.php @@ -86,7 +86,7 @@ abstract class Base */ public function add($arg) { - if ( $arg !== null || ($arg instanceof self && $arg->count() > 0) ) { + if ( $arg !== null && (!$arg instanceof self || $arg->count() > 0) ) { // If we decide to keep Expr\Base instances, we can use this check if ( ! is_string($arg)) { $class = get_class($arg); diff --git a/tests/Doctrine/Tests/ORM/Query/ExprTest.php b/tests/Doctrine/Tests/ORM/Query/ExprTest.php index d35944bf8..4d90ea1d8 100644 --- a/tests/Doctrine/Tests/ORM/Query/ExprTest.php +++ b/tests/Doctrine/Tests/ORM/Query/ExprTest.php @@ -414,4 +414,18 @@ class ExprTest extends \Doctrine\Tests\OrmTestCase $select = new Expr\Select(array('foo', 'bar')); $this->assertEquals(array('foo', 'bar'), $select->getParts()); } + + public function testAddEmpty() { + $andExpr = $this->_expr->andx(); + $andExpr->add($this->_expr->andx()); + + $this->assertEquals(0, $andExpr->count()); + } + + public function testAddNull() { + $andExpr = $this->_expr->andx(); + $andExpr->add(null); + + $this->assertEquals(0, $andExpr->count()); + } }