mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
FIX: DataObject::db() doesn't respect overloaded db types (fixes #3620)
This commit is contained in:
parent
ca9c192c65
commit
85b4ba15fc
@ -1664,19 +1664,10 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
|
||||
* @return array The database fields
|
||||
*/
|
||||
public function db($fieldName = null) {
|
||||
$classes = ClassInfo::ancestry($this);
|
||||
$good = false;
|
||||
$classes = ClassInfo::ancestry($this, true);
|
||||
$items = array();
|
||||
|
||||
foreach($classes as $class) {
|
||||
// Wait until after we reach DataObject
|
||||
if(!$good) {
|
||||
if($class == 'DataObject') {
|
||||
$good = true;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach(array_reverse($classes) as $class) {
|
||||
if(isset(self::$_cache_db[$class])) {
|
||||
$dbItems = self::$_cache_db[$class];
|
||||
} else {
|
||||
|
@ -16,18 +16,31 @@ class DataObjectTest extends SapphireTest {
|
||||
'DataObjectTest_FieldlessSubTable',
|
||||
'DataObjectTest_ValidatedObject',
|
||||
'DataObjectTest_Player',
|
||||
'DataObjectTest_TeamComment'
|
||||
'DataObjectTest_TeamComment',
|
||||
'DataObjectTest_ExtendedTeamComment'
|
||||
);
|
||||
|
||||
public function testBaseFieldsExcludedFromDb() {
|
||||
$obj = new DataObjectTest_ValidatedObject();
|
||||
|
||||
public function testDb() {
|
||||
$obj = new DataObjectTest_TeamComment();
|
||||
$dbFields = $obj->db();
|
||||
|
||||
// Assert fields are included
|
||||
$this->assertArrayHasKey('Name', $dbFields);
|
||||
|
||||
// Assert the base fields are excluded
|
||||
$this->assertArrayNotHasKey('Created', $dbFields);
|
||||
$this->assertArrayNotHasKey('LastEdited', $dbFields);
|
||||
$this->assertArrayNotHasKey('ClassName', $dbFields);
|
||||
$this->assertArrayNotHasKey('ID', $dbFields);
|
||||
|
||||
// Assert that the correct field type is returned when passing a field
|
||||
$this->assertEquals('Varchar', $obj->db('Name'));
|
||||
$this->assertEquals('Text', $obj->db('Comment'));
|
||||
|
||||
$obj = new DataObjectTest_ExtendedTeamComment();
|
||||
|
||||
// Assert overloaded fields have correct data type
|
||||
$this->assertEquals('HTMLText', $obj->db('Comment'));
|
||||
}
|
||||
|
||||
public function testValidObjectsForBaseFields() {
|
||||
@ -1443,5 +1456,11 @@ class DataObjectTest_TeamComment extends DataObject {
|
||||
|
||||
}
|
||||
|
||||
class DataObjectTest_ExtendedTeamComment extends DataObjectTest_TeamComment {
|
||||
private static $db = array(
|
||||
'Comment' => 'HTMLText'
|
||||
);
|
||||
}
|
||||
|
||||
DataObjectTest_Team::add_extension('DataObjectTest_Team_Extension');
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user