/**
  * Save all the items in this list into the RelationList
  *
  * @param RelationList $list
  */
 public function changeToList(RelationList $list)
 {
     foreach ($this->items as $key => $item) {
         if (is_object($item)) {
             $item->write();
         }
         $list->add($item, $this->extraFields[$key]);
     }
 }
 public function createDataObject($row)
 {
     // Add joined record
     $joinRow = [];
     $joinAlias = $this->manipulator->getJoinAlias();
     $prefix = $joinAlias . '_';
     foreach ($row as $key => $value) {
         if (strpos($key, $prefix) === 0) {
             $joinKey = substr($key, strlen($prefix));
             $joinRow[$joinKey] = $value;
             unset($row[$key]);
         }
     }
     // Create parent record
     $record = parent::createDataObject($row);
     // Create joined record
     if ($joinRow) {
         $joinClass = $this->manipulator->getJoinClass();
         $joinQueryParams = $this->manipulator->extractInheritableQueryParameters($this->dataQuery);
         $joinRecord = Injector::inst()->create($joinClass, $joinRow, false, $this->model, $joinQueryParams);
         $record->setJoin($joinRecord, $joinAlias);
     }
     return $record;
 }
 /**
  * Create a DataObject from the given SQL row.
  *
  * @param array $row
  * @return DataObject
  */
 protected function createDataObject($row)
 {
     // remove any composed fields
     $add = array();
     if ($this->_compositeExtraFields) {
         foreach ($this->_compositeExtraFields as $fieldName => $composed) {
             // convert joined extra fields into their composite field types.
             $value = array();
             foreach ($composed as $subField) {
                 if (isset($row[$fieldName . $subField])) {
                     $value[$subField] = $row[$fieldName . $subField];
                     // don't duplicate data in the record
                     unset($row[$fieldName . $subField]);
                 }
             }
             $obj = Object::create_from_string($this->extraFields[$fieldName], $fieldName);
             $obj->setValue($value, null, false);
             $add[$fieldName] = $obj;
         }
     }
     $dataObject = parent::createDataObject($row);
     foreach ($add as $fieldName => $obj) {
         $dataObject->{$fieldName} = $obj;
     }
     return $dataObject;
 }
 /**
  * Create a new HasManyList object.
  * Generation of the appropriate record set is left up to the caller, using the normal
  * {@link DataList} methods.  Addition arguments are used to support {@@link add()}
  * and {@link remove()} methods.
  *
  * @param string $dataClass The class of the DataObjects that this will list.
  * @param string $foreignKey The name of the foreign key field to set the ID filter against.
  */
 public function __construct($dataClass, $foreignKey)
 {
     parent::__construct($dataClass);
     $this->foreignKey = $foreignKey;
 }