{"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":"Error \"Cannot find a relationship between '{model}' and '{relationship}' when preparing: {phql}\" thrown in phalcon/cphalcon.","triggerScenarios":"Thrown at phalcon/Mvc/Model/Query.zep:4069 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"b7419de9cd0a8a3f48441ead84c9f8415d463e25","analyzedAt":"2026-08-21T06:21:18.811Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}