DboSource::index PHP Method

index() public method

Returns an array of the indexes in given datasource name.
public index ( string $model ) : array
$model string Name of model to inspect
return array Fields in table. Keys are column and unique
    public function index($model)
    {
        return array();
    }

Usage Example

 /**
  * testIndexDetection method
  *
  * @group indices
  * @return void
  */
 public function testIndexDetection()
 {
     $this->Dbo->cacheSources = false;
     $name = $this->Dbo->fullTableName('simple');
     $this->Dbo->rawQuery('CREATE TABLE ' . $name . ' (id int(11) AUTO_INCREMENT, bool tinyint(1), small_int tinyint(2), primary key(id));');
     $expected = array('PRIMARY' => array('column' => 'id', 'unique' => 1));
     $result = $this->Dbo->index('simple', false);
     $this->Dbo->rawQuery('DROP TABLE ' . $name);
     $this->assertEquals($expected, $result);
     $name = $this->Dbo->fullTableName('with_a_key');
     $this->Dbo->rawQuery('CREATE TABLE ' . $name . ' (id int(11) AUTO_INCREMENT, bool tinyint(1), small_int tinyint(2), primary key(id), KEY `pointless_bool` ( `bool` ));');
     $expected = array('PRIMARY' => array('column' => 'id', 'unique' => 1), 'pointless_bool' => array('column' => 'bool', 'unique' => 0));
     $result = $this->Dbo->index('with_a_key', false);
     $this->Dbo->rawQuery('DROP TABLE ' . $name);
     $this->assertEquals($expected, $result);
     $name = $this->Dbo->fullTableName('with_two_keys');
     $this->Dbo->rawQuery('CREATE TABLE ' . $name . ' (id int(11) AUTO_INCREMENT, bool tinyint(1), small_int tinyint(2), primary key(id), KEY `pointless_bool` ( `bool` ), KEY `pointless_small_int` ( `small_int` ));');
     $expected = array('PRIMARY' => array('column' => 'id', 'unique' => 1), 'pointless_bool' => array('column' => 'bool', 'unique' => 0), 'pointless_small_int' => array('column' => 'small_int', 'unique' => 0));
     $result = $this->Dbo->index('with_two_keys', false);
     $this->Dbo->rawQuery('DROP TABLE ' . $name);
     $this->assertEquals($expected, $result);
     $name = $this->Dbo->fullTableName('with_compound_keys');
     $this->Dbo->rawQuery('CREATE TABLE ' . $name . ' (id int(11) AUTO_INCREMENT, bool tinyint(1), small_int tinyint(2), primary key(id), KEY `pointless_bool` ( `bool` ), KEY `pointless_small_int` ( `small_int` ), KEY `one_way` ( `bool`, `small_int` ));');
     $expected = array('PRIMARY' => array('column' => 'id', 'unique' => 1), 'pointless_bool' => array('column' => 'bool', 'unique' => 0), 'pointless_small_int' => array('column' => 'small_int', 'unique' => 0), 'one_way' => array('column' => array('bool', 'small_int'), 'unique' => 0));
     $result = $this->Dbo->index('with_compound_keys', false);
     $this->Dbo->rawQuery('DROP TABLE ' . $name);
     $this->assertEquals($expected, $result);
     $name = $this->Dbo->fullTableName('with_multiple_compound_keys');
     $this->Dbo->rawQuery('CREATE TABLE ' . $name . ' (id int(11) AUTO_INCREMENT, bool tinyint(1), small_int tinyint(2), primary key(id), KEY `pointless_bool` ( `bool` ), KEY `pointless_small_int` ( `small_int` ), KEY `one_way` ( `bool`, `small_int` ), KEY `other_way` ( `small_int`, `bool` ));');
     $expected = array('PRIMARY' => array('column' => 'id', 'unique' => 1), 'pointless_bool' => array('column' => 'bool', 'unique' => 0), 'pointless_small_int' => array('column' => 'small_int', 'unique' => 0), 'one_way' => array('column' => array('bool', 'small_int'), 'unique' => 0), 'other_way' => array('column' => array('small_int', 'bool'), 'unique' => 0));
     $result = $this->Dbo->index('with_multiple_compound_keys', false);
     $this->Dbo->rawQuery('DROP TABLE ' . $name);
     $this->assertEquals($expected, $result);
 }
All Usage Examples Of DboSource::index
DboSource