mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
API CHANGE Introduced DataQuery::whereAny() and SQLQuery::whereAny()
This commit is contained in:
parent
671c8b734d
commit
9bf247cc33
@ -292,7 +292,7 @@ class DataList extends ViewableData implements SS_List {
|
||||
$SQL_Statements[] = ('"'.$fieldName.'" != \''.Convert::raw2sql($value).'\'');
|
||||
}
|
||||
}
|
||||
$this->dataQuery->where(implode(' OR ', $SQL_Statements));
|
||||
$this->dataQuery->whereAny($SQL_Statements);
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -338,6 +338,23 @@ class DataQuery {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
|
@ -406,6 +406,15 @@ class SQLQuery {
|
||||
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.
|
||||
*/
|
||||
|
9
tests/model/SQLQueryTest.php
Normal file → Executable file
9
tests/model/SQLQueryTest.php
Normal file → Executable file
@ -234,6 +234,15 @@ class SQLQueryTest extends SapphireTest {
|
||||
$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 {
|
||||
|
Loading…
Reference in New Issue
Block a user