Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

API CHANGE Decimal now allows setting a default value properly

MINOR Unit tests for Decimal field type default value through new test class DecimalTest (from r98056)

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@102571 467b73ca-7a2a-4603-9d3b-597d59a354a9
  • Loading branch information...
commit a5dde231b66971ef09b5ef326dbe88a0beba4592 1 parent 529ed1d
@chillu chillu authored
Showing with 10 additions and 4 deletions.
  1. +6 −1 core/model/MySQLDatabase.php
  2. +4 −3 core/model/fieldtypes/Decimal.php
View
7 core/model/MySQLDatabase.php
@@ -582,7 +582,12 @@ public function decimal($values){
$precision = $values['precision'];
}
- return 'decimal(' . $precision . ') not null';
+ $defaultValue = '';
+ if(isset($values['default']) && is_numeric($values['default'])) {
+ $defaultValue = ' default ' . $values['default'];
+ }
+
+ return 'decimal(' . $precision . ') not null' . $defaultValue;
}
/**
View
7 core/model/fieldtypes/Decimal.php
@@ -5,14 +5,15 @@
* @subpackage model
*/
class Decimal extends DBField {
- protected $wholeSize, $decimalSize;
+ protected $wholeSize, $decimalSize, $defaultValue;
/**
* Create a new Decimal field.
*/
- function __construct($name, $wholeSize = 9, $decimalSize = 2) {
+ function __construct($name, $wholeSize = 9, $decimalSize = 2, $defaultValue = 0) {
$this->wholeSize = isset($wholeSize) ? $wholeSize : 9;
$this->decimalSize = isset($decimalSize) ? $decimalSize : 2;
+ $this->defaultValue = $defaultValue;
parent::__construct($name);
}
@@ -25,7 +26,7 @@ function Int() {
}
function requireField() {
- $parts=Array('datatype'=>'decimal', 'precision'=>"$this->wholeSize,$this->decimalSize", 'arrayValue'=>$this->arrayValue);
+ $parts=Array('datatype'=>'decimal', 'precision'=>"$this->wholeSize,$this->decimalSize", 'default'=>$this->defaultValue, 'arrayValue'=>$this->arrayValue);
$values=Array('type'=>'decimal', 'parts'=>$parts);
DB::requireField($this->tableName, $this->name, $values);
}
Please sign in to comment.
Something went wrong with that request. Please try again.