diff --git a/runtime/lib/query/Criteria.php b/runtime/lib/query/Criteria.php index 231b8552d..147f31364 100644 --- a/runtime/lib/query/Criteria.php +++ b/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); } diff --git a/test/testsuite/runtime/query/ModelCriteriaTest.php b/test/testsuite/runtime/query/ModelCriteriaTest.php index 949aa1f51..0348058c6 100644 --- a/test/testsuite/runtime/query/ModelCriteriaTest.php +++ b/test/testsuite/runtime/query/ModelCriteriaTest.php @@ -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