Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

API CHANGE Introduced DataQuery::whereAny() and SQLQuery::whereAny()

  • Loading branch information...
commit 9bf247cc3333a691c45423e9a41cacbed809a5c9 1 parent 671c8b7
@stojg stojg authored sminnee committed
View
2  model/DataList.php
@@ -292,7 +292,7 @@ public function exclude(){
$SQL_Statements[] = ('"'.$fieldName.'" != \''.Convert::raw2sql($value).'\'');
}
}
- $this->dataQuery->where(implode(' OR ', $SQL_Statements));
+ $this->dataQuery->whereAny($SQL_Statements);
return $this;
}
View
17 model/DataQuery.php
@@ -337,6 +337,23 @@ function where($filter) {
return $this;
}
}
+
+ /**
+ * Set a WHERE with OR
+ *
+ * @param array $filter
+ * @return DataQuery
+ * @example $dataQuery->whereAny(array("Monkey = 'Chimp'", "Color = 'Brown'"));
+ */
+ function whereAny($filter) {
+ if($filter) {
+ $clone = $this;
+ $clone->query->whereAny($filter);
+ return $clone;
+ } else {
+ return $this;
+ }
+ }
/**
* Set the ORDER BY clause of this query
View
11 model/SQLQuery.php
@@ -405,7 +405,16 @@ public function where() {
return $this;
}
-
+
+ /**
+ *
+ */
+ function whereAny($filters) {
+ if(is_string($filters)) $filters = func_get_args();
+ $clause = implode(" OR ", $filters);
+ return $this->where($clause);
+ }
+
/**
* Use the disjunctive operator 'OR' to join filter expressions in the WHERE clause.
*/
View
9 tests/model/SQLQueryTest.php 100644 → 100755
@@ -234,6 +234,15 @@ public function testInnerJoin() {
$query->sql()
);
}
+
+
+ public function testWhereAny() {
+ $query = new SQLQuery();
+ $query->from( 'MyTable' );
+
+ $query->whereAny(array("Monkey = 'Chimp'", "Color = 'Brown'"));
+ $this->assertEquals("SELECT * FROM MyTable WHERE (Monkey = 'Chimp' OR Color = 'Brown')",$query->sql());
+ }
}
class SQLQueryTest_DO extends DataObject implements TestOnly {
Please sign in to comment.
Something went wrong with that request. Please try again.