Skip to content
This repository
Browse code

Merge pull request #450 from bgcc/master

combine replaces previous conditions added by filterby
  • Loading branch information...
commit 51983e4b116ffec3de697cd7349251bd2105b44a 2 parents 080c4bb + 3a93511
William Durand willdurand authored
2  runtime/lib/query/Criteria.php
@@ -822,7 +822,7 @@ public function combine($criterions = array(), $operator = self::LOGICAL_AND, $n
822 822 $firstCriterion->$operatorMethod($criterion);
823 823 }
824 824 if ($name === null) {
825   - $this->add($firstCriterion, null, null);
  825 + $this->addAnd($firstCriterion, null, null);
826 826 } else {
827 827 $this->addCond($name, $firstCriterion, null, null);
828 828 }
23 test/testsuite/runtime/query/ModelCriteriaTest.php
@@ -2496,6 +2496,29 @@ public function testExistsWithNonExistentCondition()
2496 2496 $c->where('b.Title = ?', 'jenexistepas');
2497 2497 $this->assertFalse($c->exists());
2498 2498 }
  2499 +
  2500 + public function testCombineAndFilterBy()
  2501 + {
  2502 + $params = array();
  2503 + $sql = "SELECT FROM `book` WHERE ((book.TITLE LIKE :p1 OR book.ISBN LIKE :p2) AND book.TITLE LIKE :p3)";
  2504 + $c = BookQuery::create()
  2505 + ->condition('u1', 'book.TITLE LIKE ?', '%test1%')
  2506 + ->condition('u2', 'book.ISBN LIKE ?', '%test2%')
  2507 + ->combine(array('u1', 'u2'), 'or')
  2508 + ->filterByTitle('%test3%');
  2509 + $result = BasePeer::createSelectSql($c, $params);
  2510 + $this->assertEquals($result, $sql);
  2511 +
  2512 + $params = array();
  2513 + $sql = "SELECT FROM `book` WHERE (book.TITLE LIKE :p1 AND (book.TITLE LIKE :p2 OR book.ISBN LIKE :p3))";
  2514 + $c = BookQuery::create()
  2515 + ->filterByTitle('%test3%')
  2516 + ->condition('u1', 'book.TITLE LIKE ?', '%test1%')
  2517 + ->condition('u2', 'book.ISBN LIKE ?', '%test2%')
  2518 + ->combine(array('u1', 'u2'), 'or');
  2519 + $result = BasePeer::createSelectSql($c, $params);
  2520 + $this->assertEquals($result, $sql);
  2521 + }
2499 2522 }
2500 2523
2501 2524 class TestableModelCriteria extends ModelCriteria

0 comments on commit 51983e4

Please sign in to comment.
Something went wrong with that request. Please try again.