diff --git a/forms/CheckboxSetField.php b/forms/CheckboxSetField.php index 07e6d100d..84f976408 100644 --- a/forms/CheckboxSetField.php +++ b/forms/CheckboxSetField.php @@ -181,15 +181,16 @@ class CheckboxSetField extends OptionsetField { * @param DataObject $record The record to save into */ function saveInto(DataObject $record) { - $fieldname = $this->name ; - if($fieldname && $record && ($record->has_many($fieldname) || $record->many_many($fieldname))) { + $fieldname = $this->name; + $relation = ($fieldname && $record && $record->hasMethod($fieldname)) ? $record->$fieldname() : null; + if($fieldname && $record && $relation && $relation instanceof RelationList) { $idList = array(); if($this->value) foreach($this->value as $id => $bool) { if($bool) { $idList[] = $id; } } - $record->$fieldname()->setByIDList($idList); + $relation->setByIDList($idList); } elseif($fieldname && $record) { if($this->value) { $this->value = str_replace(',', '{comma}', $this->value); diff --git a/forms/ListboxField.php b/forms/ListboxField.php index 42aeb3291..c52df9f8b 100644 --- a/forms/ListboxField.php +++ b/forms/ListboxField.php @@ -172,10 +172,11 @@ class ListboxField extends DropdownField { function saveInto(DataObject $record) { if($this->multiple) { $fieldname = $this->name; - if($fieldname && $record && ($record->has_many($fieldname) || $record->many_many($fieldname))) { + $relation = ($fieldname && $record && $record->hasMethod($fieldname)) ? $record->$fieldname() : null; + if($fieldname && $record && $relation && $relation instanceof RelationList) { $idList = (is_array($this->value)) ? array_values($this->value) : array(); if(!$record->ID) $record->write(); // record needs to have an ID in order to set relationships - $record->$fieldname()->setByIDList($idList); + $relation->setByIDList($idList); } elseif($fieldname && $record) { if($this->value) { $this->value = str_replace(',', '{comma}', $this->value);