public function Table::addIndex in Data 8
Add an index to table.
@todo: support more than one field.
1 call to Table::addIndex()
- Table::changeIndex in src/
Table.php - Change indexes of a table.
File
- src/
Table.php, line 289
Class
- Table
- Manages data access and manipulation for a single data table. Use data_create_table() or data_get_table() to instantiate an object from this class.
Namespace
Drupal\dataCode
public function addIndex($field) {
$schema = $this->table_schema;
if ($schema['fields'][$field]) {
$index = data_get_index_definition($field, $schema['fields'][$field]);
try {
\Drupal::database()
->schema()
->addIndex($this->name, $field, $index);
} catch (DatabaseSchemaObjectExistsException $e) {
throw new DataException(t('Error adding index.'));
}
$schema['indexes'][$field] = $index;
$this
->update(array(
'table_schema' => $schema,
));
drupal_get_schema($this->name, TRUE);
}
}