Set the foreign ID and type for creating a related model.

@param Model  $model
@return void
10165
protected function setForeignAttributesForCreate(Model $model)
	{
		$model->{$this->getPlainForeignKey()} = $this->getParentKey();

		$model->{last(explode('.', $this->morphType))} = $this->morphClass;
	}
78485
public function associate($model)
    {
        $this->parent->setAttribute($this->foreignKey, $model->getKey());

        $this->parent->setAttribute($this->morphType, $model->getMorphClass());

        return $this->parent->setRelation($this->relation, $model);
    }
4860
public function setRelatedModel(Model $model) {
        $this->_relatedModel = $model;
        $this->setRelatedClass(get_class($model));

        return $this;
    }
295574
public function cleanup(Model $model) {
        if ($model->id) {
            $this->resetCache($model, $model->id);
        }

        foreach ($this->_cached as $key => $value) {
            $this->deleteCache($model, $key);
        }
    }
845824
public function associate($model)
    {
        $this->parent->setAttribute(
            $this->foreignKey, $model instanceof Model ? $model->getKey() : null
        );

        $this->parent->setAttribute(
            $this->morphType, $model instanceof Model ? $model->getMorphClass() : null
        );

        return $this->parent->setRelation($this->relationName, $model);
    }
127861
public function setRelated($alias, Model $entity) {
        $foundRelation = $this->getRelationship($alias);
        if($foundRelation instanceof CustomRelationship) {
            call_user_func(array($this, 'set' . ucfirst($alias)), $entity);
        } else {
            $attribute = $foundRelation->getFields();
            $value = $foundRelation->getReferencedFields();
            if(is_array($attribute)) {
                $count = sizeOf($attribute);
                for($i = 0; $i < $count; $i++) {
                    $this->writeAttribute($attribute[$i], $entity->readAttribute($value[$i]));
                }
            } else {
                $this->writeAttribute($attribute, $entity->readAttribute($value));
            }
        }
    }
1296306
public function associate($model)
    {
        $foreignKey = $this->foreignKey;
        $pk         = $model->getPk();

        $this->parent->setAttr($foreignKey, $model->$pk);
        $this->parent->save();

        return $this->parent->setRelation($this->relation, $model);
    }
1041304
public function setModel($model, $foreignKey, $foreignKeyIds)
    {
        $this->model = $model;
        $this->foreignKey = $foreignKey;
        $this->foreignKeyIds = array_wrap($foreignKeyIds);

        $this->message = "Integrity constraint violation [{$model}] where $foreignKey in (".implode(', ', $foreignKeyIds).')';

        return $this;
    }
356379
public function setModel(\atk4\data\Model $model)
    {
        parent::setModel($model);
        $this->field = $this->field ? $this->field : $this->model->title_field;
        if ($this->autoSave && $this->model->loaded()) {
            if ($this->cb->triggered()) {
                $value = $_POST['value'] ? $_POST['value'] : null;
                $this->cb->set(function () use ($value) {
                    try {
                        $this->model[$this->field] = $this->app->ui_persistence->typecastLoadField($this->model->getElement($this->field), $value);
                        $this->model->save();

                        return $this->jsSuccess('Update successfully');
                    } catch (ValidationException $e) {
                        $this->app->terminate(json_encode([
                              'success'            => true,
                              'hasValidationError' => true,
                              'atkjs'              => $this->jsError(call_user_func($this->formatErrorMsg, $e, $value))->jsRender(),
                          ]));
                    }
                });
            }
        }

        return $this->model;
    }
226775
public function setModel(Model $model)
    {
        parent::setModel($model);
        $this->setHtmlAttribute('data-value', $this->getModelValue());

        return $this;
    }
684419
public function setModel(Model $model)
    {
        $this->model = $model;
        $this->class = get_class($model);

        return $this;
    }
878879
public function set_model( $model )
    {
        // Check that the required arguments are provided.
        foreach( $this->required_arguments() as $key )
        {
            if ( !isset($model[$key]) )
            {
                throw new \RuntimeException('The required argument "'.$key.'" was not provided for '.get_called_class());
            }
        }
        
        // Assign the name of the component as the id if no id was specified
        if( !isset($model['id']) && isset($model['name']) )
        {
            $model['id'] = $model['name'];
        }

        // A name must be specified when a component has a visibility condition
        if( isset($model['show']) && !isset($model['name']) )
        {
            throw new \RuntimeException('Components with a visibility condition (a "show" argument) must have a name');
        }
        
        $this->model = array_merge( $this->default_model(), $model );
    }
705763
public static function setRelation($modelOne, $keyOne, $modelTwo, $keyTwo): void
    {
        $relations = [$modelOne => $keyOne, $modelTwo => $keyTwo];
        self::setRelations($modelOne, $modelTwo, $relations);
    }
134562
public function setModel($model)
    {
        // convert the model class into an instance
        if (!is_object($model)) {
            $this->modelClass = $model;
            $model = new $model($this->modelId);
        } else {
            $this->modelId = $model->ids();
            $this->modelClass = get_class($model);
        }

        $this->model = $model;

        return $this;
    }
134431
public function setPrimaryModel(Model $model) {
        $this->_model = $model;
        $this->setPrimaryClass(get_class($model));

        return $this;
    }
439569
public function setHabtmData(Model $model) {
        foreach ($model->hasAndBelongsToMany as $assoc) {
            if (!$assoc['showInForm']) {
                continue;
            }

            $object = Admin::introspectModel($assoc['className']);
            $variable = Inflector::variable(Inflector::pluralize(preg_replace('/(?:_id)$/', '', $assoc['associationForeignKey'])));

            $this->Controller->set($variable, $this->getRecordList($object));
        }
    }
238518
public function fillModel(&$model, $input)
    {
        $model->{$this->getOption('foreign_key')} = $input !== 'false' ? $input : null;

        $model->__unset($this->getOption('field_name'));
    }