@param Model $model

@return FormElements|void
@throws \Illuminate\Database\Eloquent\ModelNotFoundException
556735
public function setModel(Model $model)
    {
        parent::setModel($model);

        if ($model->exists) {
            $this->setInstance($model);
            $this->loadRelationValues();
        }
    }
229766
protected function setModelAttributes($model)
    {
        $this->setModelClass(Inflector::getClassNameFromNamespace($model));

        if (!property_exists($model, 'tableName') || is_null($this->tableName)) {
            $this->setTableName(Inflector::tabilize($this->getModelClass()));
        }

        if (!property_exists($model, 'database') || is_null($this->database)) {
            $this->setDatabase($this->queryBuilder()->getDefaultConnection());
        } else {
            $this->setDatabase($this->database);
        }

        if (is_null($this->getDatabase())) {
            throw new \InvalidArgumentException(
                'Please specify database name in your model. '.get_called_class()
            );
        }

        $this->setPrimarykey();
    }
479166
public function afterDelete(Model &$model)
    {
        /** @var \T4\Orm\Model $class */
        $class = get_class($model);
        $tableName = $class::getTableName();
        /** @var \T4\Dbal\Connection $connection */
        $connection = $class::getDbConnection();

        $query = (new Query())
            ->delete()
            ->table($tableName)
            ->where('__lft>:lft AND __rgt<:rgt')
            ->params([':lft' => $model->__lft, ':rgt' => $model->__rgt]);
        $connection->execute($query);

        $this->removeFromTreeByLftRgt($connection, $tableName, $model->__lft, $model->__rgt);

        $model->__lft = 0;
        $model->__rgt = 0;
        $model->__lvl = 0;
        $model->__prt = 0;
    }
873437
protected function delete($model)
    {
        $method = $this->methods['delete'];

        if (!method_exists($this->storage, $method) || !is_callable([$this->storage, $method])) {
            throw new DeleteMethodNotFoundException(get_class($this->storage), $method);
        }

        $this->storage->$method($model);

        return true;
    }
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;
    }
1159081
public function process(Model $model)
    {
        $data = 'NULL';
        return $this->pool->render->renderSingleChild(
            $model->setData($data)->setNormal($data)->setType(static::TYPE_NULL)
        );
    }
1193229
public function setModel(Model $model)
    {
        $this->model = $model;
        $append = $this->getAppends();

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

        return $this;
    }
342817
public function append(Model $model)
    {
        $result = null;
        // If the list was filtered make sure that value is set on the model.
        if ($this->filter !== null) {
            $result = $this->filter->setFilterValuesOnModel($model);
        }
        $model->save();

        // Make sure the list is refetched.
        $this->invalidate();

        return ($result === null) ? $model : $result;
    }
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'));
    }
715152
public function setModel(\Illuminate\Database\Eloquent\Model $model) {
        $this->model = $model;
        if ($this->model instanceof ResourceInterface) {
            $this->enableAutoEagerLoading = true;
        }
    }
247353
protected function performConfiguredAddMethod(Model $model)
    {
        if ( ! $model->addNewAt() || $this->excludeFromList()) return;

        $addMethod = 'addToList' . $model->addNewAt();

        if ( ! method_exists($model, $addMethod)) {
            throw new \BadMethodCallException("Method '{$addMethod}' on listify model does not exist");
        }

        $model->$addMethod();
    }
565181
public function setModel($model)
    {
        if(!($model instanceof ModelInterface))
        {
            if(is_string($model) && strpos($model, '.') === false )
            {
                // Model names are always plural
                if(StringInflector::isSingular($model)) {
                    $model = StringInflector::pluralize($model);
                }

                $identifier         = $this->getIdentifier()->toArray();
                $identifier['path'] = array('model');
                $identifier['name'] = $model;

                $identifier = $this->getIdentifier($identifier);
            }
            else $identifier = $this->getIdentifier($model);

            $model = $identifier;
        }

        $this->_model = $model;

        return $this->_model;
    }
1354349
public static function deleteModel($model)
    {
        foreach(AnnotationManager::getPropertiesAnnotations(BeanFactory::getObjectClass($model), RelationBase::class) as $propertyName => $annotations)
        {
            if(null === $model[$propertyName])
            {
                continue;
            }
            $annotation = $annotations[0];
            Delete::parse($model, $propertyName, $annotation);
        }
    }
112484
protected function showModifier(Model $model)
    {
        $name = $this->manager->getClassName($model);

        $this->title("Modifier of Model {$name}: ");

        $modifiers = [
            'mutators' => $this->manager->getMutators($model),
            'accessors' => $this->manager->getAccessors($model),
            'scopes' => $this->manager->getScopes($model),
        ];

         $rows = [];

        foreach (max($modifiers) as $modifier) {
            foreach (['mutator', 'accessor', 'scope'] as $type) {
                $$type = '';
                $types = &$modifiers[Str::plural($type)];

                if ($types->count() > 0) {
                    $$type = $this->paintString($types->first()->getName(), 'brown');
                    unset($types[0]);
                }
            }

            $rows[] = [$mutator, $accessor, $scope];
        }

        $headers = ['mutator', 'accessor', 'scope'];

        $this->table($headers, $rows);
        
    }
248759
public function getModel($model)
    {
        $model = str_replace(':', '\\', $model);

        if (!class_exists($model)) {
            throw new ModelNotFoundException($model);
        }

        return new $model($this);
    }
595525
public function applyToModel(Model $model)
    {
        if (! $this->onlyScopeRelations && ! is_null($this->scope)) {
            $model->scope = $this->scope;
        }

        return $model;
    }
359988
public function afterDelete(Model $Model) {
		if ($this->settings[$Model->alias]['auto'] === false) {
			return;
		}
		if (!$Model->ShadowModel) {
			return;
		}
		if (isset($this->deleteUpdates[$Model->alias]) && !empty($this->deleteUpdates[$Model->alias])) {
			foreach ($this->deleteUpdates[$Model->alias] as $assocAlias => $assocIds) {
				$Model->{$assocAlias}->updateRevisions($assocIds);
			}
			unset($this->deleteUpdates[$Model->alias]);
		}
	}