diff --git a/forms/ComplexTableField.php b/forms/ComplexTableField.php index ebccb0f59..9162189fe 100755 --- a/forms/ComplexTableField.php +++ b/forms/ComplexTableField.php @@ -389,6 +389,21 @@ JS; } } + /** + * Return the record in which the CTF resides + */ + function getParentRecord() { + if($this->form && $record = $this->form->getRecord()) { + return $record; + } else { + if($this->sourceID()) { + $parentClass = DataObject::get_by_id($this->getParentClass(), $this->sourceID()); + } else { + $parentClass = singleton($this->getParentClass()); + } + } + } + /** * (Optional) Setter for a correct parent-relation-class. * Defaults to the record loaded into the surrounding form as a fallback. @@ -472,11 +487,7 @@ JS; function getFieldsFor($childData) { // See if our parent class has any many_many relations by this source class if($this->getParentClass()) { - if($this->sourceID()) { - $parentClass = DataObject::get_by_id($this->getParentClass(), $this->sourceID()); - } else { - $parentClass = singleton($this->getParentClass()); - } + $parentClass = $this->getParentRecord(); $manyManyRelations = $parentClass->many_many(); $manyManyRelationName = null;