Skip to content

Commit

Permalink
Merge pull request #450 from bgcc/master
Browse files Browse the repository at this point in the history
combine replaces previous conditions added by filterby
  • Loading branch information
willdurand committed Oct 22, 2012
2 parents 080c4bb + 3a93511 commit 51983e4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion runtime/lib/query/Criteria.php
Expand Up @@ -822,7 +822,7 @@ public function combine($criterions = array(), $operator = self::LOGICAL_AND, $n
$firstCriterion->$operatorMethod($criterion);
}
if ($name === null) {
$this->add($firstCriterion, null, null);
$this->addAnd($firstCriterion, null, null);
} else {
$this->addCond($name, $firstCriterion, null, null);
}
Expand Down
23 changes: 23 additions & 0 deletions test/testsuite/runtime/query/ModelCriteriaTest.php
Expand Up @@ -2496,6 +2496,29 @@ public function testExistsWithNonExistentCondition()
$c->where('b.Title = ?', 'jenexistepas');
$this->assertFalse($c->exists());
}

public function testCombineAndFilterBy()
{
$params = array();
$sql = "SELECT FROM `book` WHERE ((book.TITLE LIKE :p1 OR book.ISBN LIKE :p2) AND book.TITLE LIKE :p3)";
$c = BookQuery::create()
->condition('u1', 'book.TITLE LIKE ?', '%test1%')
->condition('u2', 'book.ISBN LIKE ?', '%test2%')
->combine(array('u1', 'u2'), 'or')
->filterByTitle('%test3%');
$result = BasePeer::createSelectSql($c, $params);
$this->assertEquals($result, $sql);

$params = array();
$sql = "SELECT FROM `book` WHERE (book.TITLE LIKE :p1 AND (book.TITLE LIKE :p2 OR book.ISBN LIKE :p3))";
$c = BookQuery::create()
->filterByTitle('%test3%')
->condition('u1', 'book.TITLE LIKE ?', '%test1%')
->condition('u2', 'book.ISBN LIKE ?', '%test2%')
->combine(array('u1', 'u2'), 'or');
$result = BasePeer::createSelectSql($c, $params);
$this->assertEquals($result, $sql);
}
}

class TestableModelCriteria extends ModelCriteria
Expand Down

0 comments on commit 51983e4

Please sign in to comment.