Permalink
Browse files

Merge pull request #497 from vclayton/DDC-2113

[DDC-2113] Surround WHERE clause with parens if using SQLFilter
  • Loading branch information...
2 parents 98c5b34 + ae30ce4 commit 129d6efd8585458fd4bde2a3eb9a5cac374f54fe @guilhermeblanco guilhermeblanco committed Nov 2, 2012
Showing with 17 additions and 1 deletion.
  1. +1 −1 lib/Doctrine/ORM/Query/SqlWalker.php
  2. +16 −0 tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php
@@ -1700,7 +1700,7 @@ public function walkWhereClause($whereClause)
if (count($filterClauses)) {
if ($condSql) {
- $condSql .= ' AND ';
+ $condSql = '(' . $condSql . ') AND ';
}
$condSql .= implode(' AND ', $filterClauses);
@@ -453,6 +453,22 @@ public function testWhereFilter()
$this->assertEquals(1, count($query->getResult()));
}
+ public function testWhereOrFilter()
+ {
+ $this->loadFixtureData();
+ $query = $this->_em->createQuery('select ug from Doctrine\Tests\Models\CMS\CmsGroup ug WHERE 1=1 OR 1=1');
+
+ // We get two users before enabling the filter
+ $this->assertEquals(2, count($query->getResult()));
+
+ $conf = $this->_em->getConfiguration();
+ $conf->addFilter("group_prefix", "\Doctrine\Tests\ORM\Functional\CMSGroupPrefixFilter");
+ $this->_em->getFilters()->enable("group_prefix")->setParameter("prefix", "bar_%", DBALType::STRING);
+
+ // We get one user after enabling the filter
+ $this->assertEquals(1, count($query->getResult()));
+ }
+
private function loadLazyFixtureData()
{

0 comments on commit 129d6ef

Please sign in to comment.