Update Table.php

为addTimestamps增加自定义列名
This commit is contained in:
joewulf 2016-10-17 10:39:34 +08:00 committed by 云无心
parent 43d018cb0c
commit c548b07a63

View File

@ -560,19 +560,23 @@ class Table
/**
* Add timestamp columns created_at and updated_at to the table.
*
* @param string $createdAtColumnName
* @param string $updatedAtColumnName
*
* @return Table
*/
public function addTimestamps()
public function addTimestamps($createdAtColumnName = 'created_at', $updatedAtColumnName = 'updated_at')
{
$this->addColumn('create_time', 'timestamp', [
'default' => 'CURRENT_TIMESTAMP',
'update' => ''
])
->addColumn('update_time', 'timestamp', [
$createdAtColumnName = is_null($createdAtColumnName) ? 'created_at' : $createdAtColumnName;
$updatedAtColumnName = is_null($updatedAtColumnName) ? 'updated_at' : $updatedAtColumnName;
$this->addColumn($createdAtColumnName, 'timestamp', array(
'default' => 'CURRENT_TIMESTAMP',
'update' => ''
))
->addColumn($updatedAtColumnName, 'timestamp', array(
'null' => true,
'default' => null
]);
));
return $this;
}