BUG Correct relation saving in DataObject->duplicateRelations()

This caused problems when duplicate() was used in the CMS UI
to duplicate a SiteTree object. Since every object of this type
has a ParentID relation, it copied this empty relation into
new "ghost page".

See https://github.com/silverstripe/silverstripe-cms/issues/689
This commit is contained in:
Ingo Schommer 2013-06-03 14:48:52 +02:00
parent d5510f54b3
commit f61ab7305d
2 changed files with 26 additions and 1 deletions

View File

@ -499,7 +499,7 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
}
}
} else { //one-to-one relation
$destinationObject->$name = $relations;
$destinationObject->{"{$name}ID"} = $relations->ID;
}
}
}

View File

@ -1,6 +1,8 @@
<?php
class DataObjectDuplicationTest extends SapphireTest {
protected $usesDatabase = true;
protected $extraDataObjects = array(
'DataObjectDuplicateTestClass1',
@ -28,6 +30,29 @@ class DataObjectDuplicationTest extends SapphireTest {
);
}
public function testDuplicateHasOne() {
$relationObj = new DataObjectDuplicateTestClass1();
$relationObj->text = 'class1';
$relationObj->write();
$orig = new DataObjectDuplicateTestClass2();
$orig->text = 'class2';
$orig->oneID = $relationObj->ID;
$orig->write();
$duplicate = $orig->duplicate();
$this->assertEquals($relationObj->ID, $duplicate->oneID,
'Copies has_one relationship'
);
$this->assertEquals(2, DataObjectDuplicateTestClass2::get()->Count(),
'Only creates a single duplicate'
);
$this->assertEquals(1, DataObjectDuplicateTestClass1::get()->Count(),
'Does not create duplicate of has_one relationship'
);
}
public function testDuplicateManyManyClasses() {
//create new test classes below
$one = new DataObjectDuplicateTestClass1();