octobercms/october · error · ApplicationException

backend::lang.relation.missing_model

Error message

backend::lang.relation.missing_model

What it means

initRelationInternal throws the localized relation.missing_model error when a field name is supplied but $this->model is null — the relation manager was asked to initialize against a nonexistent parent model (e.g. the parent record was not found earlier).

Solutions

  1. Ensure the parent model is loaded and passed to initRelation before relation operations
  2. Handle the case where the parent record lookup failed before initializing relations
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at modules/backend/behaviors/RelationController.php:363 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of octobercms/october@b608633a7e (2026-08-21). Data as JSON: /api/errors/5e29dd141bf17421. Report an issue: GitHub.

Appendix: source

Thrown at modules/backend/behaviors/RelationController.php:363

    {
        if ($this->originalConfig === null) {
            $this->originalConfig = $this->controller->relationGetConfig();
        }

        if ($field === null) {
            $field = post(self::PARAM_FIELD);
        }

        $this->config = $this->originalConfig;
        $this->model = $model;
        $this->field = $field;

        if (!$field) {
            return;
        }

        if (!$this->model) {
            throw new ApplicationException(Lang::get('backend::lang.relation.missing_model', [
                'class' => get_class($this->controller),
            ]));
        }

        if (!$this->model instanceof Model) {
            throw new ApplicationException(Lang::get('backend::lang.model.invalid_class', [
                'model' => get_class($this->model),
                'class' => get_class($this->controller),
            ]));
        }

        // Configuration details
        if (!$this->relationHasField($field)) {
            throw new ApplicationException(Lang::get('backend::lang.relation.missing_definition', compact('field')));
        }

        $this->applyExtraConfig($field);
        $this->alias = camel_case('relation ' . HtmlHelper::nameToId($field));

View on GitHub (pinned to b608633a7e)