Skip to content

Commit

Permalink
Fixing Mysql::describe() for timestamp.
Browse files Browse the repository at this point in the history
  • Loading branch information
okinaka committed Dec 11, 2014
1 parent ac6d5cc commit 5cff6aa
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lib/Cake/Model/Datasource/Database/Mysql.php
Expand Up @@ -352,7 +352,8 @@ public function describe($model) {
$fields[$column->Field]['unsigned'] = $this->_unsigned($column->Type);
}
if ($fields[$column->Field]['type'] === 'timestamp' && strtoupper($column->Default) === 'CURRENT_TIMESTAMP') {
$fields[$column->Field]['default'] = '';
$fields[$column->Field]['default'] = null;
$fields[$column->Field]['null'] = true;
}
if (!empty($column->Key) && isset($this->index[$column->Key])) {
$fields[$column->Field]['key'] = $this->index[$column->Key];
Expand Down
11 changes: 10 additions & 1 deletion lib/Cake/Test/Case/Model/Datasource/Database/MysqlTest.php
Expand Up @@ -906,8 +906,17 @@ public function testDescribeHandleCurrentTimestamp() {
'alias' => 'TimestampDefaultValue'
));
$result = $this->Dbo->describe($model);
$this->assertEquals('', $result['limit_date']['default']);
$this->Dbo->execute('DROP TABLE ' . $name);

$this->assertNull($result['limit_date']['default']);
$this->assertTrue($result['limit_date']['null']);

$schema = new CakeSchema(array(
'connection' => 'test',
'testdescribes' => $result
));
$result = $this->Dbo->createSchema($schema);
$this->assertContains('`limit_date` timestamp NULL,', $result);
}

/**
Expand Down

0 comments on commit 5cff6aa

Please sign in to comment.