Skip to content

Commit 6f177eb

Browse files
committed
Fix support for decimal columns with null defaults
1 parent 144d67b commit 6f177eb

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/Schema/Column/DecimalPointColumn.php

+11-1
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,21 @@ public function getPhpType() : string
4949

5050
public function getPhpCode() : string
5151
{
52+
$default = '';
53+
54+
if ($this->hasDefault()) {
55+
$default = '->setDefault('
56+
. ($this->getDefault() === null
57+
? 'null'
58+
: '\'' . $this->getDefault() . '\'')
59+
. ')';
60+
}
61+
5262
return '(new \\' . static::class . '('
5363
. $this->precision
5464
. ', ' . $this->scale
5565
. '))'
56-
. ($this->hasDefault() ? '->setDefault(\'' . $this->getDefault() . '\')' : '')
66+
. $default
5767
. $this->getNullablePhp();
5868
}
5969
}

tests/fixtures/create_table.sql

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ CREATE TABLE `transactions` (
4646
`id` int(10) NOT NULL AUTO_INCREMENT,
4747
`total` DECIMAL(12, 2) NOT NULL,
4848
`tax` DECIMAL(12, 2) NOT NULL,
49+
`other_tax` DECIMAL(12, 2) DEFAULT NULL,
4950
PRIMARY KEY (`id`)
5051
)
5152
ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;

0 commit comments

Comments
 (0)