{"record":{"id":"2b16592d6ddd66de","repo":"phalcon/cphalcon","slug":"eager-loading-the-relation-alias-requires-the","errorCode":null,"errorMessage":"Eager loading the relation '{alias}' requires the column '{column}' to be present in the selected columns","messagePattern":"Eager loading the relation '(.+?)' requires the column '(.+?)' to be present in the selected columns","errorType":"exception","errorClass":"Phalcon\\Mvc\\Model\\Exceptions\\MissingEagerKeyColumn","httpStatus":null,"severity":"error","filePath":"phalcon/Mvc/Model/Eager/Loader.zep","lineNumber":475,"sourceCode":"    protected function collectKeys(\n        array parents,\n        array fields,\n        string alias\n    ) -> array {\n        var field, parent, value;\n        array seen, values;\n\n        let seen = [];\n\n        for parent in parents {\n            let values = [];\n\n            for field in fields {\n                if typeof parent === \"object\" {\n                    let value = parent->readAttribute(field);\n                } else {\n                    if unlikely !array_key_exists(field, parent) {\n                        throw new MissingEagerKeyColumn(alias, field);\n                    }\n\n                    let value = parent[field];\n                }\n\n                let values[] = value;\n            }\n\n            if in_array(null, values, true) {\n                continue;\n            }\n\n            let seen[self::buildKey(values)] = values;\n        }\n\n        return array_values(seen);\n    }\n","sourceCodeStart":457,"sourceCodeEnd":493,"githubUrl":"https://github.com/phalcon/cphalcon/blob/b7419de9cd0a8a3f48441ead84c9f8415d463e25/phalcon/Mvc/Model/Eager/Loader.zep#L457-L493","documentation":"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.","triggerScenarios":"Thrown at phalcon/Mvc/Model/Eager/Loader.zep:475 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Add the relation's local key column to the columns list of the parent query (avoid overly restrictive column selections)","If a column map is used, ensure the attribute name matches the mapped field","Verify the relation field configuration points at an actual column returned by the parent query"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"b7419de9cd0a8a3f48441ead84c9f8415d463e25","analyzedAt":"2026-08-21T06:21:18.811Z","contentChangedAt":"2026-08-21T06:21:18.811Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}