Adding quotation marks and a connector, depending on the type
of the key.

@param integer|string $key
The key (or name) of what we are analysing.
@param Model $model
The so far prepared model we are preparing further.
429912
protected function handleKey($key, Model $model)
    {
        if (is_string($key) === true) {
            $model->setName($this->pool->encodingService->encodeString($key))
                ->setConnectorType(Connectors::ASSOCIATIVE_ARRAY);

            return;
        }

        $model->setName($key)->setConnectorType(Connectors::NORMAL_ARRAY);
    }
764250
public function creating(Model $model)
    {
        $count = method_exists($model, 'getCounter') ? $model->getCounter() : ($model::count() ?? 0);

        $column = method_exists($model, 'getReferenceColumn') ? $model->getReferenceColumn() : 'reference';

        $prefix = method_exists($model, 'referencePrefix') ? $model->referencePrefix() : config('document.prefix');

        if (Schema::hasColumn($model->getTable(), $column) && is_null($model->$column)) {
            $model->$column = generate_reference($prefix, $count);
        }
    }
10165
protected function setForeignAttributesForCreate(Model $model)
	{
		$model->{$this->getPlainForeignKey()} = $this->getParentKey();

		$model->{last(explode('.', $this->morphType))} = $this->morphClass;
	}
1221260
public function creating(Model $model)
    {
        if ($model instanceof SingleSiteInterface) {
            $site = $this->router->getActiveSite() ?: $this->site->findDefault();

            $model->{SingleSiteInterface::ATTR_SITE} = ($site ? $site->getId() : null);
        }
    }
802229
protected function updateBlameables(Model $model)
    {
        $user = $this->getActiveUser();

        if (is_null($user)) {
            return; // Todo: might be wise to implement loggin here
        }

        // Set updated-by if it has not been touched on this model
        if ($this->isBlameable($model, 'updated') && !$model->isDirty($this->getColumn($model, 'updated'))) {
            $this->setUpdatedBy($model, $user);
        }

        // Determine if we need to touch the created stamp
        if ($model->exists) {
            return;
        }

        // Set created-by if the model does not exist
        if ($this->isBlameable($model, 'created') && !$model->isDirty($this->getColumn($model, 'created'))) {
            $this->setCreatedBy($model, $user);
        }
    }
276217
public function onCustomFieldCreateOrEdit(Model $model)
    {
        $this->onList();
        Breadcrumbs::register('customfields-create-update', function($breadcrumbs) use($model) {
            $breadcrumbs->parent('customfields');
            $name = $model->exists ? 'Update custom field ' . $model->name : 'Create custom field';
            $breadcrumbs->push($name, '#');
        });

        view()->share('breadcrumbs', Breadcrumbs::render('customfields-create-update'));
    }
150410
protected function setModelForElements(Model $model)
    {
        $this->getElements()->each(function ($element) use ($model) {
            $element = $this->getElementContainer($element);

            if ($element instanceof WithModelInterface) {
                $element->setModel($model);
            }
        });

        return $this;
    }
1373025
protected function renderedShowFieldStrategies(Model $model)
    {
        $views = [];

        foreach ($this->getModelInformation()->show->fields as $key => $data) {

            if ( ! $this->allowedToUseShowFieldData($data)) {
                continue;
            }

            try {
                $instance = $this->getShowFieldFactory()->make($data->strategy);

                // Feed any extra information we can gather to the instance
                $instance->setOptions($data->options());

                if ($data->source) {
                    if (isset($this->getModelInformation()->attributes[ $data->source ])) {
                        $instance->setAttributeInformation(
                            $this->getModelInformation()->attributes[ $data->source ]
                        );
                    }
                }

                // @codeCoverageIgnoreStart
            } catch (Exception $e) {
                $message = "Failed to make show field strategy for '{$key}': \n{$e->getMessage()}";

                throw new StrategyRenderException($message, $e->getCode(), $e);
                // @codeCoverageIgnoreEnd
            }

            try {
                $views[ $key ] = $instance->render($model, $data->source);

                // @codeCoverageIgnoreStart
            } catch (Exception $e) {
                $message = "Failed to render show field '{$key}' for strategy " . get_class($instance)
                         . ": \n{$e->getMessage()}";

                throw new StrategyRenderException($message, $e->getCode(), $e);
                // @codeCoverageIgnoreEnd
            }
        }

        return $views;
    }
1201351
public function createModel($model)
    {
        $schema = new Schema();

        $tableDef = $schema->createTable($model->getMeta()->getDbTable());
        // this assumes fields set_from_name has been invoked
        $primaryKeyFields = [];
        $unique_fields = [];
        $indexes = [];
        /** @var $field Field */
        /** @var $field ForeignKey */
        foreach ($model->getMeta()->localFields as $fname => $field) {
            $colName = $field->getColumnName();
            $type = $field->dbType($this->connection);
            // if we don't have a type skip
            if (empty($type)) {
                continue;
            }
            if ($field->primaryKey) {
                $primaryKeyFields[] = $model->getMeta()->primaryKey->getColumnName();
            } elseif ($field->isUnique()) {
                $unique_fields[] = $colName;
            } elseif ($field->dbIndex) {
                $indexes[] = $colName;
            }
            $tableDef->addColumn($colName, $type, $this->getDoctrineColumnOptions($field));
            if ($field->isRelation && $field->relation && $field->dbConstraint) {
                $relField = $field->getRelatedField();
                $tableDef->addForeignKeyConstraint(
                    $relField->scopeModel->getMeta()->getDbTable(),
                    [$field->getColumnName()],
                    [$relField->getColumnName()]
                );
            }
        }
        // create the primary key
        $tableDef->setPrimaryKey($primaryKeyFields);
        // add index constraint
        if (!empty($indexes)) {
            $tableDef->addIndex($indexes);
        }
        // add unique constraint
        if (!empty($unique_fields)) {
            $tableDef->addUniqueIndex($unique_fields);
        }
        $this->createTable($tableDef);
        // many to many
        /** @var $relationField ManyToManyField */
        foreach ($model->getMeta()->localManyToMany as $name => $relationField) {
            if ($relationField->manyToMany && $relationField->relation->through->getMeta()->autoCreated) {
                $this->createModel($relationField->relation->through);
            }
        }
    }
715152
public function setModel(\Illuminate\Database\Eloquent\Model $model) {
        $this->model = $model;
        if ($this->model instanceof ResourceInterface) {
            $this->enableAutoEagerLoading = true;
        }
    }
796205
public void addCache(Object key, String className, Object model) {
		if (key == null)
			return;
		if (ModelUtil.isModel(model.getClass()))
			modelCacheManager.saveCache(key, className, model);
		else
			Debug.logError("addCache error:" + model.getClass() + " not ModelIF or @Model", module);

	}
18476
public function apply(Builder $builder, Model $model)
    {
        if ($model->getTypeKey())
        {
            $builder->where(
                $model->getTypeKeyName(),
                $model->getTypeKey()
            );
        }
    }
193582
public function asNode(Model $model)
    {
        $node = $this->client->makeNode();

        // If the key name of the model is 'id' we will need to set it properly with setId()
        // since setting it as a regular property with setProperty() won't cut it.
        if ($model->getKeyName() == 'id')
        {
            $node->setId($model->getKey());
        }

        // In this case the dev has chosen a different primary key
        // so we use it insetead.
        else
        {
            $node->setProperty($model->getKeyName(), $model->getKey());
        }

        return $node;
    }
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));
        }
    }
88694
public function buildRelationXTypeInfo(Model $model, $key)
    {
        $relation = $model->$key();

        switch (true) {

            case $relation instanceof BelongsTo:
                return $this->buildBelongsToInfo($key, $relation);

            case $relation instanceof BelongsToMany:
                return $this->buildBelongsToManyInfo($key, $relation);

            case $relation instanceof HasMany:
                return $this->buildHasManyInfo($key, $relation);

            case $relation instanceof HasOne:
                return $this->buildHasOneInfo($key, $relation);

            case $relation instanceof HasManyThrough:
                return $this->buildHasManyThroughInfo($key, $relation);

            case $relation instanceof MorphOne:
                return $this->buildMorphOneInfo($key, $relation);

            case $relation instanceof MorphMany:
                return $this->buildMorphManyInfo($key, $relation);

            default:
                $modelClass = get_class($model);
                $relationType = Type::of($relation);

                throw new UnsupportedParameterException("Result of $modelClass->$key() did not return a Relation (it returned $relationType)");
        }
    }
643303
public function setUp($model, $key = null)
    {
        ob_start();

        $this->keys[] = $key = $this->normalizeKey($model, $key);

        return $this->cache->has($key);
    }
1282476
public function link(Model $model) {
        $this->getLinked()->flush()->append($model);

        $this->getPrimaryModel()->set($this->getPrimaryForeignKey(), $model->id());

        return $this;
    }