DBIndexable::getIndexSpecs is responsible for returning a DBFields full indexable spec

This commit is contained in:
Robbie Averill 2017-07-18 15:03:56 +12:00
parent bd5782adca
commit fb18e441a7
4 changed files with 26 additions and 10 deletions

View File

@ -525,11 +525,8 @@ class DataObjectSchema
foreach ($fieldSpecs as $field => $spec) {
/** @var DBField $fieldObj */
$fieldObj = Injector::inst()->create($spec, $field);
if ($type = $fieldObj->getIndexType()) {
$this->defaultDatabaseIndexes[$class][$field] = [
'type' => $type,
'columns' => $fieldObj->getIndexSpecs(),
];
if ($indexSpecs = $fieldObj->getIndexSpecs()) {
$this->defaultDatabaseIndexes[$class][$field] = $indexSpecs;
}
}
return $this->defaultDatabaseIndexes[$class];

View File

@ -296,8 +296,15 @@ abstract class DBComposite extends DBField
public function getIndexSpecs()
{
return array_map(function ($name) {
return $this->getName() . $name;
}, array_keys((array) static::config()->get('composite_db')));
if ($type = $this->getIndexType()) {
$columns = array_map(function ($name) {
return $this->getName() . $name;
}, array_keys((array) static::config()->get('composite_db')));
return [
'type' => $type,
'columns' => $columns,
];
}
}
}

View File

@ -635,6 +635,11 @@ DBG;
public function getIndexSpecs()
{
return [$this->getName()];
if ($type = $this->getIndexType()) {
return [
'type' => $type,
'columns' => [$this->getName()],
];
}
}
}

View File

@ -42,7 +42,14 @@ interface DBIndexable
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
*/