FIX Cast DBInt value to int

This commit is contained in:
Steve Boyd 2021-07-06 16:43:54 +12:00
parent e8c14a9d5b
commit 87d076faa6
2 changed files with 27 additions and 0 deletions

View File

@ -20,6 +20,15 @@ class DBInt extends DBField
parent::__construct($name); 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. * Returns the number, with commas added as appropriate, eg “1,000.
*/ */

View File

@ -0,0 +1,18 @@
<?php
namespace SilverStripe\ORM\Tests;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\ORM\FieldType\DBInt;
class DBIntTest extends SapphireTest
{
public function testGetValueCastToInt()
{
$field = DBInt::create('MyField');
$field->setValue(3);
$this->assertSame(3, $field->getValue());
$field->setValue('3');
$this->assertSame(3, $field->getValue());
}
}