phalcon/cphalcon · error · Phalcon\Mvc\Model\Exceptions\MissingEagerKeyColumn

Eager loading the relation

Error message

Eager loading the relation '{alias}' requires the column '{column}' to be present in the selected columns

What it means

Thrown while collecting keys for an eager batch query: a parent row (array form) does not contain the field(s) the relation uses as its local key, so the IN() values for the batch query cannot be built. The column must be present in the selected columns of the parent query.

Solutions

  1. Add the relation's local key column to the columns list of the parent query (avoid overly restrictive column selections)
  2. If a column map is used, ensure the attribute name matches the mapped field
  3. Verify the relation field configuration points at an actual column returned by the parent query
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at phalcon/Mvc/Model/Eager/Loader.zep:475 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of phalcon/cphalcon@b7419de9cd (2026-08-21). Data as JSON: /api/errors/2b16592d6ddd66de. Report an issue: GitHub.

Appendix: source

Thrown at phalcon/Mvc/Model/Eager/Loader.zep:475

    protected function collectKeys(
        array parents,
        array fields,
        string alias
    ) -> array {
        var field, parent, value;
        array seen, values;

        let seen = [];

        for parent in parents {
            let values = [];

            for field in fields {
                if typeof parent === "object" {
                    let value = parent->readAttribute(field);
                } else {
                    if unlikely !array_key_exists(field, parent) {
                        throw new MissingEagerKeyColumn(alias, field);
                    }

                    let value = parent[field];
                }

                let values[] = value;
            }

            if in_array(null, values, true) {
                continue;
            }

            let seen[self::buildKey(values)] = values;
        }

        return array_values(seen);
    }

View on GitHub (pinned to b7419de9cd)