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:
parent
32f4be83b1
commit
4210969087
2 changed files with 22 additions and 2 deletions
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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)
|
||||
;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue