Skip to content

Commit

Permalink
MINOR Re-fetching relationship in ListboxField->saveInto() when deali…
Browse files Browse the repository at this point in the history
…ng with new records, to avoid errors on RelationList without foreign keys (fixes #6925)
  • Loading branch information
chillu committed Mar 9, 2012
1 parent bf6317d commit 1ba5e79
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion forms/ListboxField.php
Expand Up @@ -175,7 +175,10 @@ function saveInto(DataObject $record) {
$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) {
Expand Down

0 comments on commit 1ba5e79

Please sign in to comment.