From 0b3a3c38b3551867270be5c882d0b801e9ffe0ec Mon Sep 17 00:00:00 2001 From: zYne Date: Sun, 11 Feb 2007 22:53:35 +0000 Subject: [PATCH] Index support added! --- lib/Doctrine/Record.php | 2 +- lib/Doctrine/Table.php | 31 ++++++++++++++++++++++++++++--- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/lib/Doctrine/Record.php b/lib/Doctrine/Record.php index 2731ed550..43e15a8d7 100644 --- a/lib/Doctrine/Record.php +++ b/lib/Doctrine/Record.php @@ -1538,7 +1538,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite */ public function index($name, array $definition = array()) { - if ( ! $columns) { + if ( ! $definition) { return $this->_table->getIndex($name); } else { return $this->_table->addIndex($name, $definition); diff --git a/lib/Doctrine/Table.php b/lib/Doctrine/Table.php index f8109b00f..c5d5db34e 100644 --- a/lib/Doctrine/Table.php +++ b/lib/Doctrine/Table.php @@ -136,13 +136,13 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable * -- inheritanceMap inheritanceMap is used for inheritance mapping, keys representing columns and values * the column values that should correspond to child classes * - * -- engine database engine (mysql example: INNODB) + * -- type table type (mysql example: INNODB) * * -- charset character set * * -- collation * - * -- index the index definitions of this table + * -- indexes the index definitions of this table * * -- treeImpl the tree implementation of this table (if any) * @@ -158,7 +158,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable 'collation' => null, 'treeImpl' => null, 'treeOptions' => null, - 'index' => array(), + 'indexes' => array(), ); /** * @var Doctrine_Tree $tree tree object associated with this table @@ -412,6 +412,31 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable { return isset($this->options[$option]); } + /** + * addIndex + * + * adds an index to this table + * + * @return void + */ + public function addIndex($index, array $definition) + { + $index = $this->conn->getIndexName($index); + $this->options['indexes'][$index] = $definition; + } + /** + * getIndex + * + * @return array|boolean array on success, FALSE on failure + */ + public function getIndex($index) + { + if (isset($this->options['indexes'][$index])) { + return $this->options['indexes'][$index]; + } + + return false; + } /** * createQuery * creates a new Doctrine_Query object and adds the component name