1
0
Fork 0
mirror of synced 2025-04-01 12:26:11 +03:00

DDC-2192 - Prevent using append flag in case of where and having to avoid user confusion, because this is not allowed.

This commit is contained in:
Benjamin Eberlei 2013-01-06 10:33:57 +01:00
parent 32f4be83b1
commit 4210969087
2 changed files with 22 additions and 2 deletions

View file

@ -532,6 +532,13 @@ class QueryBuilder
*/
public function add($dqlPartName, $dqlPart, $append = false)
{
if ($append && ($dqlPartName === "where" || $dqlPartName === "having")) {
throw new \InvalidArgumentException(
"Using \$append = true does not have an effect with 'where' or 'having' ".
"parts. See QueryBuilder#andWhere() for an example for correct usage."
);
}
$isMultiple = is_array($this->_dqlParts[$dqlPartName]);
// This is introduced for backwards compatibility reasons.
@ -898,7 +905,7 @@ class QueryBuilder
$where = new Expr\Andx($args);
}
return $this->add('where', $where, true);
return $this->add('where', $where);
}
/**
@ -931,7 +938,7 @@ class QueryBuilder
$where = new Expr\Orx($args);
}
return $this->add('where', $where, true);
return $this->add('where', $where);
}
/**

View file

@ -834,4 +834,17 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase
$this->assertEquals('SELECT DISTINCT u FROM Doctrine\Tests\Models\CMS\CmsUser u', $qb->getDQL());
}
/**
* @group DDC-2192
*/
public function testWhereAppend()
{
$this->setExpectedException('InvalidArgumentException', "Using \$append = true does not have an effect with 'where' or 'having' parts. See QueryBuilder#andWhere() for an example for correct usage.");
$qb = $this->_em->createQueryBuilder()
->add('where', 'u.foo = ?1')
->add('where', 'u.bar = ?2', true)
;
}
}