{"record":{"id":"fd5dbdf1623fe634","repo":"phalcon/cphalcon","slug":"cannot-use-models-of-different-database-systems-in","errorCode":null,"errorMessage":"Cannot use models of different database systems in the same query","messagePattern":"Cannot use models of different database systems in the same query","errorType":"exception","errorClass":"Phalcon\\Mvc\\Model\\Query\\Exceptions\\MixedDatabaseSystems","httpStatus":null,"severity":"error","filePath":"phalcon/Mvc/Model/Query.zep","lineNumber":1135,"sourceCode":"                    intermediate,\n                    bindParams,\n                    bindTypes\n                );\n            } else {\n                let connection = this->getReadConnection(\n                    model,\n                    intermediate,\n                    bindParams,\n                    bindTypes\n                );\n            }\n\n            if typeof connection == \"object\" {\n                // More than one type of connection is not allowed\n                let connectionTypes[connection->getType()] = true;\n\n                if unlikely count(connectionTypes) == 2 {\n                    throw new MixedDatabaseSystems();\n                }\n            }\n        }\n\n        let columns = intermediate[\"columns\"];\n\n        let haveObjects = false,\n            haveScalars = false,\n            isComplex = false;\n\n        // Check if the resultset have objects and how many of them have\n        let numberObjects = 0;\n        let columns1 = columns;\n\n        for column in columns {\n            if unlikely typeof column != \"array\" {\n                throw new InvalidColumnDefinition();\n            }","sourceCodeStart":1117,"sourceCodeEnd":1153,"githubUrl":"https://github.com/phalcon/cphalcon/blob/b7419de9cd0a8a3f48441ead84c9f8415d463e25/phalcon/Mvc/Model/Query.zep#L1117-L1153","documentation":"In executeSelect(), connections are collected per DBMS type; when a query touches models backed by two different database systems, MixedDatabaseSystems is thrown because PHQL cannot join across engines. The faulty input is a PHQL query combining models with different adapters (e.g. MySQL + PostgreSQL).","triggerScenarios":"Thrown at phalcon/Mvc/Model/Query.zep:1135 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Query each model separately and combine results in application code","Move both models onto the same database system/connection","Split cross-database relations into separate service calls"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep related models on the same DBMS","Detect mixed connections in integration tests for complex queries"],"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"}