mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
BUGFIX: DataObjects without the Versioned decorator cannot have a "Version" field. ticket #5775. Thanks ajshort
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.4@108399 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
dc8dee7dd9
commit
900d4ea23a
@ -2208,8 +2208,9 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
|
||||
if($field == "Created" && get_parent_class($this) == "DataObject") return "SS_Datetime";
|
||||
|
||||
// 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
|
||||
$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);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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 {
|
||||
@ -176,3 +203,10 @@ class VersionedTest_Subclass extends VersionedTest_DataObject implements TestOnl
|
||||
"ExtraField" => "Varchar",
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
class VersionedTest_UnversionedWithField extends DataObject implements TestOnly {
|
||||
public static $db = array('Version' => 'Varchar(255)');
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user