{"record":{"id":"686c52a3076107c7","repo":"phalcon/cphalcon","slug":"cannot-find-a-relationship-between-model-and","errorCode":null,"errorMessage":"Cannot find a relationship between '{model}' and '{relationship}' when preparing: {phql}","messagePattern":"Cannot find a relationship between '(.+?)' and '(.+?)' when preparing: (.+?)","errorType":"exception","errorClass":"RelationshipNotFound","httpStatus":null,"severity":"error","filePath":"phalcon/Mvc/Model/Query.zep","lineNumber":4069,"sourceCode":"                        relationModel = withItem[\"name\"];\n\n                    let relation = manager->getRelationByAlias(\n                        modelName,\n                        relationModel\n                    );\n\n                    if typeof relation == \"object\" {\n                        let bestAlias = relation->getOption(\"alias\"),\n                            relationModel = relation->getReferencedModel(),\n                            eagerType = relation->getType();\n                    } else {\n                        let relation = manager->getRelationsBetween(\n                            modelName,\n                            relationModel\n                        );\n\n                        if unlikely typeof relation != \"object\" {\n                            throw new RelationshipNotFound(modelName, relationModel, this->phql);\n                        }\n\n                        let bestAlias = relation->getOption(\"alias\"),\n                            relationModel = relation->getReferencedModel(),\n                            eagerType = relation->getType();\n                    }\n\n                    let selectColumns[] = [\n                        \"type\":      PHQL_T_DOMAINALL,\n                        \"column\":    joinAlias,\n                        \"eager\":     alias,\n                        \"eagerType\": eagerType,\n                        \"balias\":    bestAlias\n                    ];\n\n                    let automaticJoins[] = [\n                        \"type\": PHQL_T_INNERJOIN,\n                        \"qualified\": [","sourceCodeStart":4051,"sourceCodeEnd":4087,"githubUrl":"https://github.com/phalcon/cphalcon/blob/b7419de9cd0a8a3f48441ead84c9f8415d463e25/phalcon/Mvc/Model/Query.zep#L4051-L4087","documentation":"Thrown in Query::prepareSelect when processing the 'with' clause: neither getRelationByAlias nor getRelationsBetween finds a relation between the queried model and the requested related model, so eager loading cannot proceed. The input at fault is the relation name in with().","triggerScenarios":"Thrown at phalcon/Mvc/Model/Query.zep:4069 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Define the relation (hasMany/belongsTo/hasOne) on the model or register its alias via getRelationByAlias.","Check the relation name spelling passed to query->with() or the with clause.","Verify the related model class name matches the one used in the relation definition."],"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"}