Skip to content

Commit

Permalink
Merge pull request #4386 from cakephp/issue-4184
Browse files Browse the repository at this point in the history
Fix CURRENT_TIMESTAMP being stored as a default value.
  • Loading branch information
ADmad committed Aug 25, 2014
2 parents 7a8cb43 + cc0acd1 commit ff3273d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/Cake/Model/Datasource/Database/Mysql.php
Expand Up @@ -351,6 +351,9 @@ public function describe($model) {
if (in_array($fields[$column->Field]['type'], $this->fieldParameters['unsigned']['types'], true)) {
$fields[$column->Field]['unsigned'] = $this->_unsigned($column->Type);
}
if ($fields[$column->Field]['type'] === 'timestamp' && strtoupper($column->Default) === 'CURRENT_TIMESTAMP') {
$fields[$column->Field]['default'] = '';
}
if (!empty($column->Key) && isset($this->index[$column->Key])) {
$fields[$column->Field]['key'] = $this->index[$column->Key];
}
Expand Down
26 changes: 26 additions & 0 deletions lib/Cake/Test/Case/Model/Datasource/Database/MysqlTest.php
Expand Up @@ -884,6 +884,32 @@ public function testDescribe() {
$this->assertTrue(isset($result['color']));
}

/**
* Test that describe() ignores `default current_timestamp` in timestamp columns.
*
* @return void
*/
public function testDescribeHandleCurrentTimestamp() {
$name = $this->Dbo->fullTableName('timestamp_default_values');
$sql = <<<SQL
CREATE TABLE $name (
id INT(11) NOT NULL AUTO_INCREMENT,
phone VARCHAR(10),
limit_date TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY(id)
);
SQL;
$this->Dbo->execute($sql);
$model = new Model(array(
'table' => 'timestamp_default_values',
'ds' => 'test',
'alias' => 'TimestampDefaultValue'
));
$result = $this->Dbo->describe($model);
$this->assertEquals('', $result['limit_date']['default']);
$this->Dbo->execute('DROP TABLE ' . $name);
}

/**
* test that a describe() gets additional fieldParameters
*
Expand Down

0 comments on commit ff3273d

Please sign in to comment.