From 42109690874e02837f8fab4be2671492e8414b09 Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Sun, 6 Jan 2013 10:33:57 +0100 Subject: [PATCH] DDC-2192 - Prevent using append flag in case of where and having to avoid user confusion, because this is not allowed. --- lib/Doctrine/ORM/QueryBuilder.php | 11 +++++++++-- tests/Doctrine/Tests/ORM/QueryBuilderTest.php | 13 +++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/lib/Doctrine/ORM/QueryBuilder.php b/lib/Doctrine/ORM/QueryBuilder.php index fdaf702c4..7f9edff86 100644 --- a/lib/Doctrine/ORM/QueryBuilder.php +++ b/lib/Doctrine/ORM/QueryBuilder.php @@ -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); } /** diff --git a/tests/Doctrine/Tests/ORM/QueryBuilderTest.php b/tests/Doctrine/Tests/ORM/QueryBuilderTest.php index 8f52fb8bf..6630bd3d6 100644 --- a/tests/Doctrine/Tests/ORM/QueryBuilderTest.php +++ b/tests/Doctrine/Tests/ORM/QueryBuilderTest.php @@ -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) + ; + } }