Skip to content

Commit

Permalink
refs # 7929 refactor uuid support to not break Backward Compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
roll4life committed Jan 15, 2016
1 parent 66f3a7e commit 47bf98c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
10 changes: 8 additions & 2 deletions lib/Cake/Model/Datasource/Database/Postgres.php
Expand Up @@ -217,6 +217,7 @@ public function describe($model) {
$length = null;
$type = 'text';
} elseif ($c->type === 'uuid') {
$type = 'uuid';
$length = 36;
} else {
$length = (int)$c->oct_length;
Expand All @@ -242,7 +243,10 @@ public function describe($model) {
if ($model instanceof Model) {
if ($c->name === $model->primaryKey) {
$fields[$c->name]['key'] = 'primary';
if ($fields[$c->name]['type'] !== 'string') {
if (
$fields[$c->name]['type'] !== 'string' &&
$fields[$c->name]['type'] !== 'uuid'
) {
$fields[$c->name]['length'] = 11;
}
}
Expand Down Expand Up @@ -699,8 +703,10 @@ public function column($real) {
return 'biginteger';
case (strpos($col, 'int') !== false && $col !== 'interval'):
return 'integer';
case (strpos($col, 'char') !== false || $col === 'uuid'):
case (strpos($col, 'char') !== false):
return 'string';
case (strpos($col, 'uuid') !== false):
return 'uuid';
case (strpos($col, 'text') !== false):
return 'text';
case (strpos($col, 'bytea') !== false):
Expand Down
3 changes: 2 additions & 1 deletion lib/Cake/Model/Datasource/DboSource.php
Expand Up @@ -344,12 +344,13 @@ public function value($data, $column = null, $null = true) {
return $this->_connection->quote($data, PDO::PARAM_LOB);
case 'boolean':
return $this->_connection->quote($this->boolean($data, true), PDO::PARAM_BOOL);
case 'string':
case 'uuid':
if ($data === '') {
return 'NULL';
} else {
return $this->_connection->quote($data, PDO::PARAM_STR);
}
case 'string':
case 'text':
return $this->_connection->quote($data, PDO::PARAM_STR);
default:
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/Model/Model.php
Expand Up @@ -1982,7 +1982,7 @@ protected function _doSave($data = null, $options = array()) {
*/
protected function _isUUIDField($field) {
$field = $this->schema($field);
return $field['length'] == 36 && in_array($field['type'], array('string', 'binary'));
return $field['length'] == 36 && in_array($field['type'], array('string', 'binary', 'uuid'));
}

/**
Expand Down

0 comments on commit 47bf98c

Please sign in to comment.