ENHANCEMENT Checking for instanceof DataObject instead of has_one() in DataObject->update() to support virtual relations as well (fix to r63531)

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@63554 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Ingo Schommer 2008-10-02 22:47:01 +00:00
parent 6694936cc8
commit 882b4bc4e1

View File

@ -406,7 +406,7 @@ class DataObject extends ViewableData implements DataObjectInterface {
foreach($relations as $i=>$relation) { foreach($relations as $i=>$relation) {
// no support for has_many or many_many relationships, // no support for has_many or many_many relationships,
// as the updater wouldn't know which object to write to (or create) // as the updater wouldn't know which object to write to (or create)
if($relObj->has_one($relation)) { if($relObj->$relation() instanceof DataObject) {
$relObj = $relObj->$relation(); $relObj = $relObj->$relation();
// If the intermediate relationship objects have been created, then write them // If the intermediate relationship objects have been created, then write them
@ -414,7 +414,7 @@ class DataObject extends ViewableData implements DataObjectInterface {
} else { } else {
user_error( user_error(
"DataObject::update(): Can't traverse relationship '$relation'," . "DataObject::update(): Can't traverse relationship '$relation'," .
"it has to be a has_one relationship returning a single DataObject", "it has to be a has_one relationship or return a single DataObject",
E_USER_NOTICE E_USER_NOTICE
); );
// unset relation object so we don't write properties to the wrong object // unset relation object so we don't write properties to the wrong object
@ -422,6 +422,7 @@ class DataObject extends ViewableData implements DataObjectInterface {
break; break;
} }
} }
if($relObj) { if($relObj) {
$relObj->$fieldName = $v; $relObj->$fieldName = $v;
$relObj->write(); $relObj->write();