mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
BUGFIX: DataObjects without the Versioned decorator cannot have a "Version" field. ticket #5775. Thanks ajshort (from r108399)
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@112725 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
c4a72efd52
commit
2058ee31ee
@ -2259,8 +2259,9 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
|
|||||||
if($field == "Created" && get_parent_class($this) == "DataObject") return "SS_Datetime";
|
if($field == "Created" && get_parent_class($this) == "DataObject") return "SS_Datetime";
|
||||||
|
|
||||||
// Add fields from Versioned decorator
|
// Add fields from Versioned decorator
|
||||||
if($field == "Version") return $this->hasExtension('Versioned') ? "Int" : false;
|
if($field == 'Version' && $this->hasExtension('Versioned')) {
|
||||||
|
return 'Int';
|
||||||
|
}
|
||||||
// get cached fieldmap
|
// get cached fieldmap
|
||||||
$fieldMap = isset(self::$cache_has_own_table_field[$this->class]) ? self::$cache_has_own_table_field[$this->class] : null;
|
$fieldMap = isset(self::$cache_has_own_table_field[$this->class]) ? self::$cache_has_own_table_field[$this->class] : null;
|
||||||
|
|
||||||
|
@ -159,6 +159,33 @@ class VersionedTest extends SapphireTest {
|
|||||||
|
|
||||||
Versioned::reading_stage($origStage);
|
Versioned::reading_stage($origStage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers DataObject::hasOwnTableDatabaseField()
|
||||||
|
*/
|
||||||
|
public function testHasOwnTableDatabaseFieldWithVersioned() {
|
||||||
|
$noversion = new DataObject();
|
||||||
|
$versioned = new VersionedTest_DataObject();
|
||||||
|
$versionedSub = new VersionedTest_Subclass();
|
||||||
|
$versionField = new VersionedTest_UnversionedWithField();
|
||||||
|
|
||||||
|
$this->assertFalse(
|
||||||
|
(bool) $noversion->hasOwnTableDatabaseField('Version'),
|
||||||
|
'Plain models have no version field.'
|
||||||
|
);
|
||||||
|
$this->assertEquals(
|
||||||
|
'Int', $versioned->hasOwnTableDatabaseField('Version'),
|
||||||
|
'The versioned ext adds an Int version field.'
|
||||||
|
);
|
||||||
|
$this->assertEquals(
|
||||||
|
'Int', $versionedSub->hasOwnTableDatabaseField('Version'),
|
||||||
|
'Sub-classes of a versioned model have a Version field.'
|
||||||
|
);
|
||||||
|
$this->assertEquals(
|
||||||
|
'Varchar', $versionField->hasOwnTableDatabaseField('Version'),
|
||||||
|
'Models w/o Versioned can have their own Version field.'
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class VersionedTest_DataObject extends DataObject implements TestOnly {
|
class VersionedTest_DataObject extends DataObject implements TestOnly {
|
||||||
@ -176,3 +203,10 @@ class VersionedTest_Subclass extends VersionedTest_DataObject implements TestOnl
|
|||||||
"ExtraField" => "Varchar",
|
"ExtraField" => "Varchar",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ignore
|
||||||
|
*/
|
||||||
|
class VersionedTest_UnversionedWithField extends DataObject implements TestOnly {
|
||||||
|
public static $db = array('Version' => 'Varchar(255)');
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user