BUGFIX Only loading value in a CompositeDBField through DataObject->getField() if either the value exists, or the record was previously saved

ENHANCEMENT Getting composite db field definitions in DataObject->hasOwnTableDatabaseField() when dealing with a CompositeDBField class

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@76097 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Ingo Schommer 2009-05-05 07:55:46 +00:00
parent 3e18112b32
commit b4ec97506a

View File

@ -901,7 +901,6 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
}
}
}
$this->extend('augmentWrite', $manipulation);
// New records have their insert into the base data table done first, so that they can pass the
@ -938,7 +937,6 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
if($writeComponents) {
$this->writeComponents(true);
}
return $this->record['ID'];
}
@ -1818,7 +1816,12 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
$constructor = $helperPair['castingHelper'];
$fieldName = $field;
$fieldObj = eval($constructor);
if(isset($this->record[$field])) $fieldObj->setValue($this->record[$field], $this->record);
// write value only if either the field value exists,
// or a valid record has been loaded from the database
$value = (isset($this->record[$field])) ? $this->record[$field] : null;
if($value || $this->exists()) $fieldObj->setValue($value, $this->record);
$this->record[$field] = $fieldObj;
return $this->record[$field];
@ -2000,6 +2003,14 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
if(!$fieldMap) {
// all $db fields on this specific class (no parents)
$fieldMap = $this->uninherited('db', true);
if($fieldMap) foreach($fieldMap as $fieldname => $fieldtype){
if(ClassInfo::classImplements($fieldtype, 'CompositeDBField')){
$combined_db = singleton($fieldtype)->composite_db();
foreach($combined_db as $name => $type){
$fieldMap[$fieldname.$name] = $type;
}
}
}
// all has_one relations on this specific class,
// add foreign key