Permalink
Browse files

Merge pull request #564 from sminnee/trac-7529

BUG: exclude() clears previously selected filters() (Trac #7529)
  • Loading branch information...
2 parents bafda93 + 1b57689 commit 32913d47f0e17f0a6444f3e08fee9f68cccc0c6b @halkyon halkyon committed Jun 22, 2012
Showing with 29 additions and 4 deletions.
  1. +1 −1 model/DataQuery.php
  2. +15 −1 model/SQLQuery.php
  3. +11 −0 tests/model/DataListTest.php
  4. +2 −2 tests/model/SQLQueryTest.php
View
@@ -461,7 +461,7 @@ function where($filter) {
function whereAny($filter) {
if($filter) {
$clone = $this;
- $clone->query->whereAny($filter);
+ $clone->query->addWhereAny($filter);
return $clone;
} else {
return $this;
View
@@ -738,14 +738,28 @@ public function where($where) {
return $this->setWhere($where);
}
+ public function whereAny($where) {
+ Deprecation::notice('3.0', 'Please use setWhereAny() or setWhereAny() instead!');
+ return $this->setWhereAny($where);
+ }
+
/**
* @param String|array $filters Predicate(s) to set, as escaped SQL statements.
*/
- function whereAny($filters) {
+ function setWhereAny($filters) {
if(is_string($filters)) $filters = func_get_args();
$clause = implode(" OR ", $filters);
return $this->setWhere($clause);
}
+
+ /**
+ * @param String|array $filters Predicate(s) to set, as escaped SQL statements.
+ */
+ function addWhereAny($filters) {
+ if(is_string($filters)) $filters = func_get_args();
+ $clause = implode(" OR ", $filters);
+ return $this->addWhere($clause);
+ }
/**
* Use the disjunctive operator 'OR' to join filter expressions in the WHERE clause.
@@ -437,6 +437,17 @@ public function testMultipleExclude() {
$list->exclude(array('Name'=>'Bob', 'Comment'=>'This is a team comment by Bob'));
$this->assertEquals(2, $list->count());
}
+
+ /**
+ * Test that if an exclude() is applied to a filter(), the filter() is still preserved.
+ */
+ public function testExcludeOnFilter() {
+ $list = DataObjectTest_TeamComment::get();
+ $list = $list->filter('Comment', 'Phil is a unique guy, and comments on team2');
+ $list = $list->exclude('Name', 'Bob');
+
+ $this->assertContains('WHERE ("Comment" = \'Phil is a unique guy, and comments on team2\') AND ("Name" != \'Bob\')', $list->sql());
+ }
/**
* $list->exclude(array('Name'=>'bob, 'Age'=>array(21, 43))); // exclude bob with Age 21 or 43
@@ -258,11 +258,11 @@ public function testInnerJoin() {
);
}
- public function testWhereAny() {
+ public function testSetWhereAny() {
$query = new SQLQuery();
$query->setFrom('MyTable');
- $query->whereAny(array("Monkey = 'Chimp'", "Color = 'Brown'"));
+ $query->setWhereAny(array("Monkey = 'Chimp'", "Color = 'Brown'"));
$this->assertEquals("SELECT * FROM MyTable WHERE (Monkey = 'Chimp' OR Color = 'Brown')",$query->sql());
}

0 comments on commit 32913d4

Please sign in to comment.