Open maritechpro opened 1 year ago
Adjust field TimestampableBehavior::parameters
/**
* @var array<string, mixed>
*/
protected $parameters = [
'create_column' => 'created_at',
'update_column' => 'updated_at',
'disable_created_at' => 'false',
'disable_updated_at' => 'false',
'is_timestamp' => 'true',
];
Add method TimestampableBehavior::isTimestamp() :
/**
* @return bool
*/
protected function isTimestamp(): bool
{
return $this->booleanValue($this->getParameter('is_timestamp'));
}
Adjust method TimestampableBehavior::modifyTable() :
/**
* Add the create_column and update_columns to the current table
*
* @return void
*/
public function modifyTable(): void
{
$table = $this->getTable();
if ($this->withCreatedAt() && !$table->hasColumn($this->getParameter('create_column'))) {
$table->addColumn([
'name' => $this->getParameter('create_column'),
'type' => $this->isTimestamp() ? 'TIMESTAMP' : 'DATETIME',
]);
}
if ($this->withUpdatedAt() && !$table->hasColumn($this->getParameter('update_column'))) {
$table->addColumn([
'name' => $this->getParameter('update_column'),
'type' => $this->isTimestamp() ? 'TIMESTAMP' : 'DATETIME',
]);
}
}
Hey, I'm opening a PR with your code @maritechpro and will try to add some tests.
FRW-2182 extend TimestampableBehavior with is_timestamp parameter to allow configuration of datetime type for created_at and updated_at
Behavior should be extendable on 2.0.0-beta2 (2.0.1-beta2) and 2.0.0-beta3 (2.0.1-beta3) versions. Thank you.