mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
BUG Correct behaviour for empty filter array (as per 3.1)
This commit is contained in:
parent
e07f80014c
commit
732e705bbf
@ -56,6 +56,10 @@ class ExactMatchFilter extends SearchFilter {
|
||||
// For queries using the default collation (no explicit case) we can use the WHERE .. IN .. syntax,
|
||||
// providing simpler SQL than many WHERE .. OR .. fragments.
|
||||
$column = $this->getDbName();
|
||||
// If values is an empty array, fall back to 3.1 behaviour and use empty string comparison
|
||||
if(empty($values)) {
|
||||
$values = array('');
|
||||
}
|
||||
$placeholders = DB::placeholders($values);
|
||||
return $query->where(array(
|
||||
"$column IN ($placeholders)" => $values
|
||||
@ -109,6 +113,10 @@ class ExactMatchFilter extends SearchFilter {
|
||||
// For queries using the default collation (no explicit case) we can use the WHERE .. NOT IN .. syntax,
|
||||
// providing simpler SQL than many WHERE .. AND .. fragments.
|
||||
$column = $this->getDbName();
|
||||
// If values is an empty array, fall back to 3.1 behaviour and use empty string comparison
|
||||
if(empty($values)) {
|
||||
$values = array('');
|
||||
}
|
||||
$placeholders = DB::placeholders($values);
|
||||
return $query->where(array(
|
||||
"$column NOT IN ($placeholders)" => $values
|
||||
|
@ -897,6 +897,26 @@ class DataListTest extends SapphireTest {
|
||||
$this->assertEquals(array('Bob'), $parameters);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test exact match filter with empty array items
|
||||
*/
|
||||
public function testEmptyFilter() {
|
||||
$list = DataObjectTest_TeamComment::get();
|
||||
$list = $list->exclude('Name', array());
|
||||
|
||||
$sql = $list->sql($parameters);
|
||||
$this->assertSQLContains('WHERE (("DataObjectTest_TeamComment"."Name" NOT IN (?)))', $sql);
|
||||
$this->assertEquals(array(''), $parameters);
|
||||
|
||||
|
||||
$list = DataObjectTest_TeamComment::get();
|
||||
$list = $list->filter('Name', array());
|
||||
|
||||
$sql = $list->sql($parameters);
|
||||
$this->assertSQLContains('WHERE ("DataObjectTest_TeamComment"."Name" IN (?))', $sql);
|
||||
$this->assertEquals(array(''), $parameters);
|
||||
}
|
||||
|
||||
/**
|
||||
* $list->exclude(array('Name'=>'bob, 'Age'=>array(21, 43))); // exclude bob with Age 21 or 43
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user