mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
FIX: Don't auto-generate indexes for Text field types (fixes #7900)
This commit is contained in:
parent
fcf0796dbd
commit
ebd3fb6526
@ -3421,7 +3421,15 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($this->hasOwnTableDatabaseField($column) && !array_key_exists($column, $indexes)) {
|
||||
list($fieldType) = SS_Object::parse_class_spec($this->db($column));
|
||||
$isAutoIndexable = (Config::inst()->get($fieldType, 'auto_indexable')
|
||||
|| Config::inst()->get("DB{$fieldType}", 'auto_indexable'));
|
||||
|
||||
if (
|
||||
$this->hasOwnTableDatabaseField($column)
|
||||
&& !array_key_exists($column, $indexes)
|
||||
&& $isAutoIndexable
|
||||
) {
|
||||
$indexes[$column] = true;
|
||||
}
|
||||
} catch (InvalidArgumentException $e) { }
|
||||
|
@ -60,6 +60,14 @@ abstract class DBField extends ViewableData {
|
||||
*/
|
||||
private static $default_search_filter_class = 'PartialMatchFilter';
|
||||
|
||||
/**
|
||||
* Flag to indicate whether this data type is safe to automatically generate an index for
|
||||
*
|
||||
* @var bool
|
||||
* @config
|
||||
*/
|
||||
private static $auto_indexable = true;
|
||||
|
||||
/**
|
||||
* @var $default mixed Default-value in the database.
|
||||
* Might be overridden on DataObject-level, but still useful for setting defaults on
|
||||
|
@ -32,6 +32,8 @@ class Text extends StringField {
|
||||
'LimitWordCountXML' => 'HTMLText',
|
||||
);
|
||||
|
||||
private static $auto_indexable = false;
|
||||
|
||||
/**
|
||||
* (non-PHPdoc)
|
||||
* @see DBField::requireField()
|
||||
|
@ -216,6 +216,11 @@ class DataObjectSchemaGenerationTest extends SapphireTest {
|
||||
$indexes = $object->databaseIndexes();
|
||||
$this->assertArrayHasKey('Sort', $indexes);
|
||||
$this->assertEquals('unique', $indexes['Sort']);
|
||||
|
||||
// make sure Text fields don't get indexes automatically - these can be db-driver dependent
|
||||
$object = new DataObjectSchemaGenerationTest_SortedByText();
|
||||
$indexes = $object->databaseIndexes();
|
||||
$this->assertArrayNotHasKey('Description', $indexes);
|
||||
}
|
||||
}
|
||||
|
||||
@ -266,3 +271,13 @@ class DataObjectSchemaGenerationTest_Sorted extends DataObject implements TestOn
|
||||
|
||||
private static $default_sort = "Sort";
|
||||
}
|
||||
|
||||
class DataObjectSchemaGenerationTest_SortedByText extends DataObject implements TestOnly {
|
||||
private static $db = array(
|
||||
'Title' => 'Varchar',
|
||||
'Description' => 'Text',
|
||||
'Sort' => 'Int',
|
||||
);
|
||||
|
||||
private static $default_sort = "Description";
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user