combine replaces previous conditions added by filterby #450

Merged
merged 2 commits into from Oct 22, 2012
View
2 runtime/lib/query/Criteria.php
@@ -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);
}
View
23 test/testsuite/runtime/query/ModelCriteriaTest.php
@@ -2493,6 +2493,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