Skip to content

Commit

Permalink
Add key to reflected schema.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Mar 25, 2013
1 parent b7f1848 commit 1dc32f2
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/Cake/Model/Datasource/Database/Connection.php
Expand Up @@ -462,6 +462,9 @@ public function describe($table) {
'default' => $row['Default'],
'length' => $length,
];
if (!empty($row['Key'])) {
$schema[$row['Field']]['key'] = $this->_driver->keyType($row['Key']);
}
}
return $schema;
}
Expand Down
21 changes: 21 additions & 0 deletions lib/Cake/Model/Datasource/Database/Dialect/MysqlDialectTrait.php
Expand Up @@ -63,9 +63,29 @@ public function describeTableSql($table) {
return ["SHOW FULL COLUMNS FROM " . $this->quoteIdentifier($table), []];
}

/**
* Convert a platform specific index type to the abstract type
*
* @param string $key The key type to convert.
* @return string The abstract key type (primary, unique, index)
*/
public function keyType($key) {
if ($key === 'PRI') {
return 'primary';
}
if ($key === 'MUL') {
return 'index';
}
if ($key === 'uni') {
return 'unique';
}
}

/**
* Convert a MySQL column type into an abstract type.
*
* The returnned type will be a type that Cake\Model\Datasource\Database\Type can handle.
*
* @param string $column The column type + length
* @return array List of (type, length)
*/
Expand Down Expand Up @@ -110,4 +130,5 @@ public function columnType($column) {
}
return 'text';
}

}
Expand Up @@ -243,6 +243,7 @@ public function testDescribeTable() {
'null' => false,
'default' => null,
'length' => 20,
'key' => 'primary',
],
'title' => [
'type' => 'string',
Expand Down

0 comments on commit 1dc32f2

Please sign in to comment.