From d5179adb01779a313da1df80be05ec35bbaac53d Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Fri, 13 Dec 2013 12:06:22 +0100 Subject: [PATCH] Improved index docs --- docs/en/reference/dataobject.md | 53 +++++++++++++++++++++------------ 1 file changed, 34 insertions(+), 19 deletions(-) diff --git a/docs/en/reference/dataobject.md b/docs/en/reference/dataobject.md index df8767d17..8f62b533d 100644 --- a/docs/en/reference/dataobject.md +++ b/docs/en/reference/dataobject.md @@ -255,28 +255,43 @@ already enforce these permissions. 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 through the `DataObject::$indexes` map, which maps index names to descriptor -arrays that represent each index. - -The general pattern for the descriptor arrays is +arrays that represent each index. There's several supported notations: :::php - array('type' => 'index|unique|fulltext', 'value' => '"FieldA","FieldB"') - -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)',); + # Simple private static $indexes = array( - 'Name_IDX' => array('type' => 'unique', 'value' => '"Name"'), - 'OtherField_IDX' => 'unique ("OtherField")', + '' => true + ); + + # Advanced + private static $indexes = array( + '' => array('type' => '', 'value' => '""') + ); + + # SQL + private static $indexes = array( + '' => 'unique("")' + ); + +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