mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
FIX: Duplicating many_many relationships looses the extra fields in 4.0
This commit is contained in:
parent
e2c8c80f02
commit
fe4b90edc0
@ -459,8 +459,20 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
|
||||
// Copy all components from source to destination
|
||||
$source = $sourceObject->getManyManyComponents($manyManyName);
|
||||
$dest = $destinationObject->getManyManyComponents($manyManyName);
|
||||
|
||||
if ($source instanceof UnsavedRelationList) {
|
||||
$extraFieldNames = array();
|
||||
} else {
|
||||
$extraFieldNames = $source->getExtraFields();
|
||||
}
|
||||
|
||||
foreach ($source as $item) {
|
||||
$dest->add($item);
|
||||
// Merge extra fields
|
||||
$extraFields = array();
|
||||
foreach ($extraFieldNames as $fieldName => $fieldType) {
|
||||
$extraFields[$fieldName] = $item->getField($fieldName);
|
||||
}
|
||||
$dest->add($item, $extraFields);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -102,7 +102,7 @@ class DataObjectDuplicationTest extends SapphireTest
|
||||
|
||||
//create relations
|
||||
$one->twos()->add($two);
|
||||
$one->threes()->add($three);
|
||||
$one->threes()->add($three, array('TestExtra'=>'three'));
|
||||
|
||||
$one = DataObject::get_by_id(DataObjectDuplicationTest\Class1::class, $one->ID);
|
||||
$two = DataObject::get_by_id(DataObjectDuplicationTest\Class2::class, $two->ID);
|
||||
@ -161,6 +161,12 @@ class DataObjectDuplicationTest extends SapphireTest
|
||||
$threeCopy->ones()->First()->ID,
|
||||
"Match between relation of copy and the original"
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'three',
|
||||
$oneCopy->threes()->byID($three->ID)->TestExtra,
|
||||
"Match between extra field of copy and the original"
|
||||
);
|
||||
}
|
||||
|
||||
public function testDuplicateManyManyFiltered()
|
||||
|
@ -20,4 +20,10 @@ class Class1 extends DataObject implements TestOnly
|
||||
private static $many_many = array(
|
||||
'threes' => Class3::class
|
||||
);
|
||||
|
||||
private static $many_many_extraFields = array(
|
||||
'threes' => array(
|
||||
'TestExtra' => 'Varchar'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user