Object relational mapping - Indexes - Adding indexes.php 1.25 KB
Newer Older
1

hansbrix's avatar
hansbrix committed
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
You can add indexes by simple calling Doctrine_Record::index('indexName', $definition) where $definition is the
definition array.



An example of adding a simple index to field called 'name':



<code type="php">
class IndexTest extends Doctrine_Record
{
    public function setTableDefinition()
    {
        \$this->hasColumn('name', 'string');

        \$this->index('myindex', array('fields' => 'name');
    }
}
?></code>



An example of adding a multi-column index to field called 'name':



<code type="php">
class MultiColumnIndexTest extends Doctrine_Record
{
    public function setTableDefinition() 
    {
        \$this->hasColumn('name', 'string');
        \$this->hasColumn('code', 'string');

        \$this->index('myindex', array('fields' => array('name', 'code')));
    }
}
?></code>



An example of adding a multiple indexes on same table:



<code type="php">
class MultipleIndexTest extends Doctrine_Record
{
    public function setTableDefinition() 
    {
        \$this->hasColumn('name', 'string');
        \$this->hasColumn('code', 'string');
        \$this->hasColumn('age', 'integer');

        \$this->index('myindex', array('fields' => array('name', 'code')));
        \$this->index('ageindex', array('fields' => array('age'));
    }
}
?></code>