lib/components/dataInterface/connectors/generic/DataSource.php
public function buildLocalAttributes(Model $foreignModel, $localModel = null, $fieldsMap = null)
    {
        $a = [];
        if (is_null($fieldsMap)) {
            $fieldsMap = $this->map;
        }
        foreach ($fieldsMap as $localKey => $fieldMap) {
            if ($localKey === $this->localPrimaryKeyName) {
                continue;
            }
            $value = $fieldMap->extractValue($this, $foreignModel);
            if ($fieldMap->testIgnore($value)) {
                continue;
            }
            $taxonomyId = null;
            if (isset($fieldMap->taxonomy) && isset($fieldMap->taxonomy['taxonomy_type'])) {
                $taxonomyTypeItem = Yii::$app->collectors['taxonomies']->getOne($fieldMap->taxonomy['taxonomy_type']);
                if (($taxonomyType = $taxonomyTypeItem->object) && isset($taxonomyType)) {
                    if (isset($fieldMap->taxonomy['taxonomy_system_id'])
                        && ($taxonomy = $taxonomyTypeItem->getTaxonomy($fieldMap->taxonomy['taxonomy_system_id']))
                        && (isset($taxonomy))
                    ) {
                        $taxonomyId = [$taxonomy->primaryKey];
                    }
                }
            }

            if (strpos($fieldMap->localField, ':') !== false) {
                // we're feeding the relations
                $relationKey = $value;
                $value = false;
                $fields = [];
                if (!empty($localModel)) {
                    $fields = $localModel->getFields();
                }
                if (!empty($relationKey)) {
                    $fieldParts = explode(':', $fieldMap->localField);
                    $checkField = $fieldParts;
                    $checkField[2] = '';
                    $checkField = implode(':', $checkField);
                    if (isset($fields[$checkField]) && !empty($fields[$checkField]->model->taxonomy_id)) {
                        $taxonomyId = $fields[$checkField]->model->taxonomy_id;
                    }

                    if ($fieldParts[0] === 'child') {
                        $relationship = $this->dummyLocalModel->objectTypeItem->getChild($fieldParts[1]);
                        $relatedType = !empty($relationship) ? $relationship->child : false;
                        $currentRelationsFunction = 'child';
                    } else {
                        $relationship = $this->dummyLocalModel->objectTypeItem->getParent($fieldParts[1]);
                        $relatedType = !empty($relationship) ? $relationship->parent : false;
                        $currentRelationsFunction = 'parent';
                    }
                    if (!$relatedType) {
                        continue;
                    }

                    $relatedObject = null;
                    if (!isset($a['relationModels'])) {
                        $a['relationModels'] = [];
                    }
                    $fieldKey = $fieldParts[0] . '_object_id';
                    if (empty($fieldParts[2]) && (!is_array($relationKey) || isset($relationKey[0]))) {
                        if (!is_array($relationKey)) {
                            $relationKey = [$relationKey];
                        }
                        foreach ($relationKey as $subkey) {
                            // we're just matching to an existing object's primary key
                            if (($relatedObject = $this->module->getLocalObject($relatedType->primaryModel, $subkey)) && is_object($relatedObject)) {
                                $relation = [$fieldKey => $relatedObject->primaryKey];
                                if (isset($taxonomyId)) {
                                    $relation['taxonomy_id'] = $taxonomyId;
                                    $taxonomyId = null;
                                }
                                $a['relationModels'][] = $relation;
                            }
                        }
                    } else {
                        $valueMap = [];
                        // we're creating or updating an existing related object's field
                        if (is_array($relationKey)) {
                            // the localRelatedField is a dummy; build/search for object using this hash
                            $valueMap = $relationKey;
                        } elseif (isset($fieldParts[2])) {
                            $localRelatedField = $fieldParts[2];
                            $valueMap = [$localRelatedField => $relationKey];
                        }
                        if (($relatedObject = $this->updateLocalObject($relatedType, $valueMap, $fieldMap, $localModel)) && is_object($relatedObject)) {
                            $relation = [$fieldKey => $relatedObject->primaryKey];
                            if (isset($taxonomyId)) {
                                $relation['taxonomy_id'] = $taxonomyId;
                                $taxonomyId = null;
                            }
                            $a['relationModels'][] = $relation;
                        }
                    }
                }
            } elseif (!empty($fieldMap->foreignModel)) {
                $relationKey = $value;
                $value = false;
                if (!empty($relationKey)) {
                    // we're filling a local related _id field with another foreign object
                    if (($relatedObject = $this->module->getForeignObject($fieldMap->foreignModel, $relationKey)) && is_object($relatedObject)) {
                        $value = $relatedObject->primaryKey;
                    }
                }
            }
            if ($value !== false) {
                $a[$fieldMap->localField] = $value;
            }
        }

        return $a;
    }
public function buildLocalAttributes(Model $foreignModel, $localModel = null, $fieldsMap = null)
    {
        $a = [];
        if (is_null($fieldsMap)) {
            $fieldsMap = $this->map;
        }
        foreach ($fieldsMap as $localKey => $fieldMap) {
            if ($localKey === $this->localPrimaryKeyName) {
                continue;
            }
            $value = $fieldMap->extractValue($this, $foreignModel);
            if ($fieldMap->testIgnore($value)) {
                continue;
            }
            $taxonomyId = null;
            if (isset($fieldMap->taxonomy) && isset($fieldMap->taxonomy['taxonomy_type'])) {
                $taxonomyTypeItem = Yii::$app->collectors['taxonomies']->getOne($fieldMap->taxonomy['taxonomy_type']);
                if (($taxonomyType = $taxonomyTypeItem->object) && isset($taxonomyType)) {
                    if (isset($fieldMap->taxonomy['taxonomy_system_id'])
                        && ($taxonomy = $taxonomyTypeItem->getTaxonomy($fieldMap->taxonomy['taxonomy_system_id']))
                        && (isset($taxonomy))
                    ) {
                        $taxonomyId = [$taxonomy->primaryKey];
                    }
                }
            }

            if (strpos($fieldMap->localField, ':') !== false) {
                // we're feeding the relations
                $relationKey = $value;
                $value = false;
                $fields = [];
                if (!empty($localModel)) {
                    $fields = $localModel->getFields();
                }
                if (!empty($relationKey)) {
                    $fieldParts = explode(':', $fieldMap->localField);
                    $checkField = $fieldParts;
                    $checkField[2] = '';
                    $checkField = implode(':', $checkField);
                    if (isset($fields[$checkField]) && !empty($fields[$checkField]->model->taxonomy_id)) {
                        $taxonomyId = $fields[$checkField]->model->taxonomy_id;
                    }

                    if ($fieldParts[0] === 'child') {
                        $relationship = $this->dummyLocalModel->objectTypeItem->getChild($fieldParts[1]);
                        $relatedType = !empty($relationship) ? $relationship->child : false;
                        $currentRelationsFunction = 'child';
                    } else {
                        $relationship = $this->dummyLocalModel->objectTypeItem->getParent($fieldParts[1]);
                        $relatedType = !empty($relationship) ? $relationship->parent : false;
                        $currentRelationsFunction = 'parent';
                    }
                    if (!$relatedType) {
                        continue;
                    }

                    $relatedObject = null;
                    if (!isset($a['relationModels'])) {
                        $a['relationModels'] = [];
                    }
                    $fieldKey = $fieldParts[0] . '_object_id';
                    if (empty($fieldParts[2]) && (!is_array($relationKey) || isset($relationKey[0]))) {
                        if (!is_array($relationKey)) {
                            $relationKey = [$relationKey];
                        }
                        foreach ($relationKey as $subkey) {
                            // we're just matching to an existing object's primary key
                            if (($relatedObject = $this->module->getLocalObject($relatedType->primaryModel, $subkey)) && is_object($relatedObject)) {
                                $relation = [$fieldKey => $relatedObject->primaryKey];
                                if (isset($taxonomyId)) {
                                    $relation['taxonomy_id'] = $taxonomyId;
                                    $taxonomyId = null;
                                }
                                $a['relationModels'][] = $relation;
                            }
                        }
                    } else {
                        $valueMap = [];
                        // we're creating or updating an existing related object's field
                        if (is_array($relationKey)) {
                            // the localRelatedField is a dummy; build/search for object using this hash
                            $valueMap = $relationKey;
                        } elseif (isset($fieldParts[2])) {
                            $localRelatedField = $fieldParts[2];
                            $valueMap = [$localRelatedField => $relationKey];
                        }
                        if (($relatedObject = $this->updateLocalObject($relatedType, $valueMap, $fieldMap, $localModel)) && is_object($relatedObject)) {
                            $relation = [$fieldKey => $relatedObject->primaryKey];
                            if (isset($taxonomyId)) {
                                $relation['taxonomy_id'] = $taxonomyId;
                                $taxonomyId = null;
                            }
                            $a['relationModels'][] = $relation;
                        }
                    }
                }
            } elseif (!empty($fieldMap->foreignModel)) {
                $relationKey = $value;
                $value = false;
                if (!empty($relationKey)) {
                    // we're filling a local related _id field with another foreign object
                    if (($relatedObject = $this->module->getForeignObject($fieldMap->foreignModel, $relationKey)) && is_object($relatedObject)) {
                        $value = $relatedObject->primaryKey;
                    }
                }
            }
            if ($value !== false) {
                $a[$fieldMap->localField] = $value;
            }
        }

        return $a;
    }
[[@doctodo method_description:buildLocalAttributes]].

@param cascade\components\dataInterface\connectors\generic\Model $foreignModel [[@doctodo param_description:foreignModel]]
@param [[@doctodo param_type:localModel]]                        $localModel   [[@doctodo param_description:localModel]] [optional]
@param [[@doctodo param_type:fieldsMap]]                         $fieldsMap    [[@doctodo param_description:fieldsMap]] [optional]

@return [[@doctodo return_type:buildLocalAttributes]] [[@doctodo return_description:buildLocalAttributes]]