Skip to content

Commit

Permalink
Merge pull request #898 from kairichard/fix-default-type-size-with-scale
Browse files Browse the repository at this point in the history
Fix default type size with scale
  • Loading branch information
marcj committed Mar 23, 2015
2 parents 8bd5656 + b9eff7b commit e6e18a2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Propel/Generator/Platform/DefaultPlatform.php
Expand Up @@ -1400,7 +1400,7 @@ public function normalizeTable(Table $table)

foreach ($table->getColumns() as $column) {
if ($column->getSize() && $defaultSize = $this->getDefaultTypeSize($column->getType())) {
if (intval($column->getSize()) === $defaultSize) {
if (null === $column->getScale() && intval($column->getSize()) === $defaultSize) {
$column->setSize(null);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Propel/Generator/Reverse/MysqlSchemaParser.php
Expand Up @@ -207,7 +207,7 @@ public function getColumnFromRow($row, Table $table)
if ($matches[3]) {
$sqlType = $row['Type'];
}
if (isset(static::$defaultTypeSizes[$nativeType]) && $size === static::$defaultTypeSizes[$nativeType]) {
if (isset(static::$defaultTypeSizes[$nativeType]) && null == $scale && $size === static::$defaultTypeSizes[$nativeType]) {
$size = null;
}
} elseif (preg_match('/^(\w+)\(/', $row['Type'], $matches)) {
Expand Down
15 changes: 15 additions & 0 deletions tests/Propel/Tests/Generator/Platform/MysqlPlatformTest.php
Expand Up @@ -839,4 +839,19 @@ public function testVendorOptionsQuoting()
$this->assertEquals($expected, $this->getPlatform()->getAddTableDDL($table));
}


public function testNormalizeTable()
{
$column = new Column('price', 'DECIMAL');
$column->getDomain()->copy($this->getPlatform()->getDomainForType('DECIMAL'));
$column->setSize(10);
$column->setScale(3);
$table = new Table('prices');
$table->addColumns([$column]);
$this->getPlatform()->normalizeTable($table);
$this->assertEquals("`price` DECIMAL(10,3)", $this->getPlatform()->getColumnDDL($column));
}



}

0 comments on commit e6e18a2

Please sign in to comment.