Permalink
Browse files

Merge pull request #450 from bgcc/master

combine replaces previous conditions added by filterby
  • Loading branch information...
2 parents 080c4bb + 3a93511 commit 51983e4b116ffec3de697cd7349251bd2105b44a @willdurand willdurand committed Oct 22, 2012
Showing with 24 additions and 1 deletion.
  1. +1 −1 runtime/lib/query/Criteria.php
  2. +23 −0 test/testsuite/runtime/query/ModelCriteriaTest.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);
}
@@ -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

0 comments on commit 51983e4

Please sign in to comment.