Stores a submitted value on a model

@param Model  $model
@param string $source
@param mixed  $value
547823
public function store(Model $model, $source, $value)
    {
        if ( ! $this->isTranslated()) {
            $this->performStore($model, $source, $value);
            return;
        }

        /** @var Model|Translatable $model */

        if ( ! is_array($value)) {
            throw new UnexpectedValueException("Value should be in per-locale array format for translatable data");
        }

        foreach ($value as $locale => $singleValue) {

            // Safeguard: use empty string if non-nullable translated field is null
            if (null === $singleValue && ! $this->isNullable()) {
                $singleValue = '';
            }

            $this->performStore($model->translateOrNew($locale), $source, $singleValue);
        }
    }
184073
public function render(Model $model, $source)
    {
        $source = $this->resolveModelSource($model, $source);

        return '#' . $model->getKey() . ': ' . $source;
    }
718092
protected function _allowEmpty(Model $model, $field, $value) {
        if (isset($this->_validations[$field]['required'])) {
            $rule = $this->_validations[$field]['required'];
            $required = isset($rule['rule'][1]) ? $rule['rule'][1] : true;

            if ($this->_isEmpty($value)) {
                if ($rule['allowEmpty']) {
                    return true;

                } else if ($required) {
                    return false;
                }
            }
        }

        return false;
    }
665514
public function style(Model $model, $source)
    {
        if ( ! $this->attributeData) {
            return null;
        }

        switch ($this->attributeData->cast) {

            case AttributeCast::INTEGER:
            case AttributeCast::FLOAT:
                return 'column-right';

            case AttributeCast::DATE:
                return 'column-date';

            // default omitted on purpose
        }

        return null;
    }
493199
public function save($con = null)
    {
        if (!method_exists($this->getFullyQualifiedModel(), 'save')) {
            throw new ReadOnlyModelException('Cannot save objects on a read-only model');
        }
        if (null === $con) {
            $con = $this->getWriteConnection();
        }
        $con->transaction(function () use ($con) {
            $obj = $this->getWorkerObject();
            foreach ($this as $element) {
                $obj->clear();
                $obj->fromArray($element);
                $obj->setNew($obj->isPrimaryKeyNull());
                $obj->save($con);
            }
        });
    }
719492
public function detach($model, string $relation, Model $value)
    {
        if (! $model instanceof Model) {
            $model = $this->find($model);
        }

        $model->$relation()->detach($value);
    }
588027
public function apply(Builder $builder, Model $model)
    {
        $column = $model->getQualifiedPublishedAtColumn();

        $builder->where($column, '=', 1);

        $this->addWithDrafts($builder);
    }
1196356
public function saved(Model $model)
    {
        $attributes = $this->processAttributes(Request::input('attributes'));
        $this->syncAttributes($model, $attributes);
    }
192049
protected function setSource( $value, ?string $key = null ) {
    if( $key === null ) $this->_source = $value === null ? [] : $value;
    else if( $value === null ) unset( $this->_source[ $key ] );
    else $this->_source[ $key ] = $value;

    // reset iterations and clean caches
    $this->rewind();
    $this->clean();
  }
156355
public function render(Model $model, $source)
    {
        $source = $this->resolveModelSource($model, $source);

        if ( ! ($source instanceof AttachmentInterface)) {
            throw new UnexpectedValueException("Paperclip strategy expects Attachment as source");
        }

        return view(static::VIEW, [
            'exists'      => $source->size() > 0,
            'filename'    => $source->originalFilename(),
            'url'         => $source->url(),
        ]);
    }
529885
def _store_cached_source_variable(self, source_id, name, value):
        
        source_state = self._source_state.setdefault(source_id, {})
        name = name.lower()
        source_state[name] = value
        logger.debug("Source Cache store S[%d].%s = %s",
                     source_id, name, value)
        for callback in self._source_callbacks:
            callback(source_id, name, value)
371917
protected function insertModelBeforeElement(Model &$model, Model &$element)
    {
        if ($element->isNew())
            throw new Exception('Target model should be saved before insert');

        $element->refreshTreeColumns();

        /** @var \T4\Orm\Model $class */
        $class = get_class($model);
        $tableName = $class::getTableName();
        /** @var \T4\Dbal\Connection $connection */
        $connection = $class::getDbConnection();

        $this->expandTreeBeforeElement($element, $model->getTreeWidth());

        if (!$model->isNew()) {

            $model->refreshTreeColumns();
            $diff = $element->__lft - $model->__lft;
            $lvldiff = $element->__lvl - $model->__lvl;

            $query = (new Query())
                ->update()
                ->table($tableName)
                ->values([
                    '__lft' => '__lft + :diff',
                    '__rgt' => '__rgt + :diff',
                    '__lvl' => '__lvl + :lvldiff',
                    '__prt' => 'CASE WHEN __id=:id THEN :parentid ELSE __prt END',
                ])
                ->where('__lft>=:lft AND __rgt<=:rgt')
                ->params([':id' => $model->getPk(), 'parentid'=>$element->__prt, ':lft' => $model->__lft, ':rgt' => $model->__rgt, ':diff' => $diff, ':lvldiff' => $lvldiff]);
            $connection->execute($query);

            $this->removeFromTreeByElement($model);

        } else {
            // TODO: этот вариант тоже рассмотреть
            throw new Exception('Save this model before move');
        }

        // TODO: рассчитывать
        $model->refreshTreeColumns();
        $element->refreshTreeColumns();

    }
317197
public function confrim(Model $model, $value, $val) {
		$value = current($value);
		$val = Hash::get($model->data,$val);
		return ($value === $val);
	}
463260
protected function saveModel(Model $model, array $options = []) {
		if ($model->isInsertForced()) {
			unset($model->_id);
			$model->unforceInsert();
		}
		
		// Update
		if (isset($model->_id)) {
			$data = $model->getDataForUpdate();
			unset($data['_id']);

			$id = $this->normalizeId($model->_id);
			
			return $this->getAdapter()->update(
				$this->getTableName(),
				['_id'  => $id],
				['$set' => $data],
				$options
			);
		}
		
		// Insert
		return $this->getAdapter()->insert(
			$this->getTableName(),
			$model->getDataForInsert(),
			$options
		);
	}
323769
public function saveToModel(Model $model, Request $request)
    {
        $parameters = $this->parseFieldParameters();
        $isMulti = isset($parameters['maxFileCount']) && $parameters['maxFileCount'] > 1 ? true : false;

        if (! $isMulti) {
            return parent::saveToModel($model, $request);
        }

        return $this;
    }
1229449
public function save($con = null)
    {
        if (!method_exists($this->getFullyQualifiedModel(), 'save')) {
            throw new ReadOnlyModelException('Cannot save objects on a read-only model');
        }
        if (null === $con) {
            $con = $this->getWriteConnection();
        }
        $con->transaction(function () use ($con) {
            /** @var $element ActiveRecordInterface */
            foreach ($this as $element) {
                $element->save($con);
            }
        });
    }
1372244
public function setValue(Model $model)
    {
        if ($this->relation) {
            if (!$relationValue = $model->{$this->relation}) {
                return $this;
            }

            $this->value = $relationValue;
        } else {
            $this->value = $model->getAttribute($this->name);
        }

        return $this;
    }