mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
parent
ce11c47d00
commit
24efc7edf8
@ -360,7 +360,8 @@ class ArrayList extends ViewableData implements SS_List, SS_Filterable, SS_Sorta
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Parse column specification, considering possible ansi sql quoting
|
// Parse column specification, considering possible ansi sql quoting
|
||||||
if(preg_match('/^"?(?<column>[^"\s]+)"?(\s+(?<direction>((asc)|(desc))(ending)?))?$/i', $column, $match)) {
|
// Note that table prefix is allowed, but discarded
|
||||||
|
if(preg_match('/^("?(?<table>[^"\s]+)"?\\.)?"?(?<column>[^"\s]+)"?(\s+(?<direction>((asc)|(desc))(ending)?))?$/i', $column, $match)) {
|
||||||
$column = $match['column'];
|
$column = $match['column'];
|
||||||
if(empty($direction) && !empty($match['direction'])) {
|
if(empty($direction) && !empty($match['direction'])) {
|
||||||
$direction = $match['direction'];
|
$direction = $match['direction'];
|
||||||
@ -448,7 +449,7 @@ class ArrayList extends ViewableData implements SS_List, SS_Filterable, SS_Sorta
|
|||||||
}
|
}
|
||||||
|
|
||||||
$multisortArgs[] = &$originalKeys;
|
$multisortArgs[] = &$originalKeys;
|
||||||
|
|
||||||
$list = clone $this;
|
$list = clone $this;
|
||||||
// As the last argument we pass in a reference to the items that all the sorting will be applied upon
|
// As the last argument we pass in a reference to the items that all the sorting will be applied upon
|
||||||
$multisortArgs[] = &$list->items;
|
$multisortArgs[] = &$list->items;
|
||||||
|
@ -274,6 +274,30 @@ class ArrayListTest extends SapphireTest {
|
|||||||
array('Name' => 'Steve')
|
array('Name' => 'Steve')
|
||||||
));
|
));
|
||||||
|
|
||||||
|
// Quoted name name with table
|
||||||
|
$list4 = $list->sort('"Record"."Name"');
|
||||||
|
$this->assertEquals($list4->toArray(), array(
|
||||||
|
(object) array('Name' => 'Bob'),
|
||||||
|
array('Name' => 'John'),
|
||||||
|
array('Name' => 'Steve')
|
||||||
|
));
|
||||||
|
|
||||||
|
// Quoted name name with table (desc)
|
||||||
|
$list5 = $list->sort('"Record"."Name" DESC');
|
||||||
|
$this->assertEquals($list5->toArray(), array(
|
||||||
|
array('Name' => 'Steve'),
|
||||||
|
array('Name' => 'John'),
|
||||||
|
(object) array('Name' => 'Bob')
|
||||||
|
));
|
||||||
|
|
||||||
|
// Table without quotes
|
||||||
|
$list6 = $list->sort('Record.Name');
|
||||||
|
$this->assertEquals($list6->toArray(), array(
|
||||||
|
(object) array('Name' => 'Bob'),
|
||||||
|
array('Name' => 'John'),
|
||||||
|
array('Name' => 'Steve')
|
||||||
|
));
|
||||||
|
|
||||||
// Check original list isn't altered
|
// Check original list isn't altered
|
||||||
$this->assertEquals($list->toArray(), array(
|
$this->assertEquals($list->toArray(), array(
|
||||||
array('Name' => 'Steve'),
|
array('Name' => 'Steve'),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user