mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Improved index docs
This commit is contained in:
parent
daf30878b6
commit
d5179adb01
@ -255,28 +255,43 @@ already enforce these permissions.
|
|||||||
It is sometimes desirable to add indexes to your data model, whether to
|
It is sometimes desirable to add indexes to your data model, whether to
|
||||||
optimize queries or add a uniqueness constraint to a field. This is done
|
optimize queries or add a uniqueness constraint to a field. This is done
|
||||||
through the `DataObject::$indexes` map, which maps index names to descriptor
|
through the `DataObject::$indexes` map, which maps index names to descriptor
|
||||||
arrays that represent each index.
|
arrays that represent each index. There's several supported notations:
|
||||||
|
|
||||||
The general pattern for the descriptor arrays is
|
|
||||||
|
|
||||||
:::php
|
:::php
|
||||||
array('type' => 'index|unique|fulltext', 'value' => '"FieldA","FieldB"')
|
# Simple
|
||||||
|
|
||||||
You can also express the descriptor as a string.
|
|
||||||
|
|
||||||
:::php
|
|
||||||
'unique ("Name")'
|
|
||||||
|
|
||||||
|
|
||||||
Note that some databases support more keywords for 'type' than shown above.
|
|
||||||
|
|
||||||
Example: a unique index on a field
|
|
||||||
|
|
||||||
:::php
|
|
||||||
private static $db = array('SEOName' => 'Varchar(255)',);
|
|
||||||
private static $indexes = array(
|
private static $indexes = array(
|
||||||
'Name_IDX' => array('type' => 'unique', 'value' => '"Name"'),
|
'<column-name>' => true
|
||||||
'OtherField_IDX' => 'unique ("OtherField")',
|
);
|
||||||
|
|
||||||
|
# Advanced
|
||||||
|
private static $indexes = array(
|
||||||
|
'<index-name>' => array('type' => '<type>', 'value' => '"<column-name>"')
|
||||||
|
);
|
||||||
|
|
||||||
|
# SQL
|
||||||
|
private static $indexes = array(
|
||||||
|
'<index-name>' => 'unique("<column-name>")'
|
||||||
|
);
|
||||||
|
|
||||||
|
The "advanced" notation varies between database drivers, but all of them support the following keys:
|
||||||
|
|
||||||
|
* `index`: Standard index
|
||||||
|
* `unique`: Index plus uniqueness constraint on the value
|
||||||
|
* `fulltext`: Fulltext content index
|
||||||
|
|
||||||
|
In order to use more database specific or complex index notations,
|
||||||
|
we also support raw SQL for as a value in the `$indexes` definition.
|
||||||
|
Keep in mind this will likely make your code less portable between databases.
|
||||||
|
|
||||||
|
Example: A combined index on a two fields.
|
||||||
|
|
||||||
|
:::php
|
||||||
|
private static $db = array(
|
||||||
|
'MyField' => 'Varchar',
|
||||||
|
'MyOtherField' => 'Varchar',
|
||||||
|
);
|
||||||
|
private static $indexes = array(
|
||||||
|
'MyIndexName' => array('type' => 'index', 'value' => '"MyField","MyOtherField"'),
|
||||||
);
|
);
|
||||||
|
|
||||||
## API Documentation
|
## API Documentation
|
||||||
|
Loading…
Reference in New Issue
Block a user