Skip to content

Commit

Permalink
Merge pull request #497 from vclayton/DDC-2113
Browse files Browse the repository at this point in the history
[DDC-2113] Surround WHERE clause with parens if using SQLFilter
  • Loading branch information
guilhermeblanco committed Nov 2, 2012
2 parents 98c5b34 + ae30ce4 commit 129d6ef
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/Doctrine/ORM/Query/SqlWalker.php
Expand Up @@ -1700,7 +1700,7 @@ public function walkWhereClause($whereClause)

if (count($filterClauses)) {
if ($condSql) {
$condSql .= ' AND ';
$condSql = '(' . $condSql . ') AND ';
}

$condSql .= implode(' AND ', $filterClauses);
Expand Down
16 changes: 16 additions & 0 deletions tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php
Expand Up @@ -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()
{
Expand Down

0 comments on commit 129d6ef

Please sign in to comment.