diff --git a/src/ORM/FieldType/DBInt.php b/src/ORM/FieldType/DBInt.php index f7863c813b5..eb283f4e919 100644 --- a/src/ORM/FieldType/DBInt.php +++ b/src/ORM/FieldType/DBInt.php @@ -20,6 +20,15 @@ public function __construct($name = null, $defaultVal = 0) parent::__construct($name); } + /** + * Ensure int values are always returned. + * This is for mis-configured databases that return strings. + */ + public function getValue() + { + return (int) $this->value; + } + /** * Returns the number, with commas added as appropriate, eg “1,000”. */ diff --git a/tests/php/ORM/DBIntTest.php b/tests/php/ORM/DBIntTest.php new file mode 100644 index 00000000000..554d80232a1 --- /dev/null +++ b/tests/php/ORM/DBIntTest.php @@ -0,0 +1,18 @@ +setValue(3); + $this->assertSame(3, $field->getValue()); + $field->setValue('3'); + $this->assertSame(3, $field->getValue()); + } +}