Skip to content

Commit

Permalink
Fix support for decimal columns with null defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
muglug committed Mar 12, 2021
1 parent 144d67b commit 6f177eb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/Schema/Column/DecimalPointColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,21 @@ public function getPhpType() : string

public function getPhpCode() : string
{
$default = '';

if ($this->hasDefault()) {
$default = '->setDefault('
. ($this->getDefault() === null
? 'null'
: '\'' . $this->getDefault() . '\'')
. ')';
}

return '(new \\' . static::class . '('
. $this->precision
. ', ' . $this->scale
. '))'
. ($this->hasDefault() ? '->setDefault(\'' . $this->getDefault() . '\')' : '')
. $default
. $this->getNullablePhp();
}
}
1 change: 1 addition & 0 deletions tests/fixtures/create_table.sql
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ CREATE TABLE `transactions` (
`id` int(10) NOT NULL AUTO_INCREMENT,
`total` DECIMAL(12, 2) NOT NULL,
`tax` DECIMAL(12, 2) NOT NULL,
`other_tax` DECIMAL(12, 2) DEFAULT NULL,
PRIMARY KEY (`id`)
)
ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;

0 comments on commit 6f177eb

Please sign in to comment.