From 1ba5e79e3b766fbc90c0074106185a86fc3be1dd Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Fri, 9 Mar 2012 22:32:12 +0100 Subject: [PATCH] MINOR Re-fetching relationship in ListboxField->saveInto() when dealing with new records, to avoid errors on RelationList without foreign keys (fixes #6925) --- forms/ListboxField.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/forms/ListboxField.php b/forms/ListboxField.php index c52df9f8b..5ad9d7460 100644 --- a/forms/ListboxField.php +++ b/forms/ListboxField.php @@ -175,7 +175,10 @@ class ListboxField extends DropdownField { $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 + if(!$record->ID) { + $record->write(); // record needs to have an ID in order to set relationships + $relation = ($fieldname && $record && $record->hasMethod($fieldname)) ? $record->$fieldname() : null; + } $relation->setByIDList($idList); } elseif($fieldname && $record) { if($this->value) {