mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
DBIndexable::getIndexSpecs is responsible for returning a DBFields full indexable spec
This commit is contained in:
parent
bd5782adca
commit
fb18e441a7
@ -525,11 +525,8 @@ class DataObjectSchema
|
|||||||
foreach ($fieldSpecs as $field => $spec) {
|
foreach ($fieldSpecs as $field => $spec) {
|
||||||
/** @var DBField $fieldObj */
|
/** @var DBField $fieldObj */
|
||||||
$fieldObj = Injector::inst()->create($spec, $field);
|
$fieldObj = Injector::inst()->create($spec, $field);
|
||||||
if ($type = $fieldObj->getIndexType()) {
|
if ($indexSpecs = $fieldObj->getIndexSpecs()) {
|
||||||
$this->defaultDatabaseIndexes[$class][$field] = [
|
$this->defaultDatabaseIndexes[$class][$field] = $indexSpecs;
|
||||||
'type' => $type,
|
|
||||||
'columns' => $fieldObj->getIndexSpecs(),
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $this->defaultDatabaseIndexes[$class];
|
return $this->defaultDatabaseIndexes[$class];
|
||||||
|
@ -296,8 +296,15 @@ abstract class DBComposite extends DBField
|
|||||||
|
|
||||||
public function getIndexSpecs()
|
public function getIndexSpecs()
|
||||||
{
|
{
|
||||||
return array_map(function ($name) {
|
if ($type = $this->getIndexType()) {
|
||||||
|
$columns = array_map(function ($name) {
|
||||||
return $this->getName() . $name;
|
return $this->getName() . $name;
|
||||||
}, array_keys((array) static::config()->get('composite_db')));
|
}, array_keys((array) static::config()->get('composite_db')));
|
||||||
|
|
||||||
|
return [
|
||||||
|
'type' => $type,
|
||||||
|
'columns' => $columns,
|
||||||
|
];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -635,6 +635,11 @@ DBG;
|
|||||||
|
|
||||||
public function getIndexSpecs()
|
public function getIndexSpecs()
|
||||||
{
|
{
|
||||||
return [$this->getName()];
|
if ($type = $this->getIndexType()) {
|
||||||
|
return [
|
||||||
|
'type' => $type,
|
||||||
|
'columns' => [$this->getName()],
|
||||||
|
];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,14 @@ interface DBIndexable
|
|||||||
public function getIndexType();
|
public function getIndexType();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the field(s) that should be used if this instance is indexed
|
* Returns the index specifications for the field instance, for example:
|
||||||
|
*
|
||||||
|
* <code>
|
||||||
|
* [
|
||||||
|
* 'type' => 'unique',
|
||||||
|
* 'columns' => ['FieldName']
|
||||||
|
* ]
|
||||||
|
* </code>
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user