Merge pull request #8146 from open-sausages/pulls/3/fix-weird-crash

BUG Fix crash on ID in default_sort
This commit is contained in:
Robbie Averill 2018-06-07 15:57:42 +12:00 committed by GitHub
commit 1d0cffd0e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 11 deletions

View File

@ -1959,7 +1959,10 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
$items = isset($items) ? array_merge((array) $items, $dbItems) : $dbItems; $items = isset($items) ? array_merge((array) $items, $dbItems) : $dbItems;
} }
} }
// If we requested a non-existant named field return null instead of all fields
if ($fieldName) {
return null;
}
return $items; return $items;
} }
@ -3433,16 +3436,18 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
if ($table && strtolower($table) !== strtolower($this->class)) { if ($table && strtolower($table) !== strtolower($this->class)) {
continue; continue;
} }
// Skip already indexed columns
list($fieldType) = SS_Object::parse_class_spec($this->db($column)); if (array_key_exists($column, $indexes)) {
$isAutoIndexable = (Config::inst()->get($fieldType, 'auto_indexable') continue;
|| Config::inst()->get("DB{$fieldType}", 'auto_indexable')); }
// Get field type (including fixed fields) on this table, if it exists
if ( $fieldType = $this->hasOwnTableDatabaseField($column);
$this->hasOwnTableDatabaseField($column) if (!$fieldType) {
&& !array_key_exists($column, $indexes) continue;
&& $isAutoIndexable }
) { $isAutoIndexable = Config::inst()->get($fieldType, 'auto_indexable')
|| Config::inst()->get("DB{$fieldType}", 'auto_indexable');
if ($isAutoIndexable) {
$indexes[$column] = true; $indexes[$column] = true;
} }
} catch (InvalidArgumentException $e) { } } catch (InvalidArgumentException $e) { }

View File

@ -1857,6 +1857,8 @@ class DataObjectTest_Fixture extends DataObject implements TestOnly {
'DateField.Nice' => 'Date' 'DateField.Nice' => 'Date'
); );
private static $default_sort = '"DataObjectTest_Fixture"."ID" ASC';
private static $searchable_fields = array(); private static $searchable_fields = array();
public function populateDefaults() { public function populateDefaults() {