{"record":{"id":"ef1ba26f83e1105f","repo":"phalcon/cphalcon","slug":"cannot-build-the-query-invalid-condition","errorCode":null,"errorMessage":"Cannot build the query. Invalid condition","messagePattern":"Cannot build the query\\. Invalid condition","errorType":"exception","errorClass":"BuilderConditionInvalid","httpStatus":null,"severity":"error","filePath":"phalcon/Mvc/Model/Query/Builder.zep","lineNumber":731,"sourceCode":"            if unlikely empty models {\n                throw new ModelRequired();\n            }\n        } else {\n            if unlikely !models {\n                throw new ModelRequired();\n            }\n        }\n\n        let conditions = this->conditions;\n\n        if is_numeric(conditions) {\n            /**\n             * If the conditions is a single numeric field. We internally create\n             * a condition using the related primary key\n             */\n            if typeof models == \"array\" {\n                if unlikely count(models) > 1 {\n                    throw new BuilderConditionInvalid();\n                }\n\n                let model = models[0];\n            } else {\n                let model = models;\n            }\n\n            /**\n             * Get the models metadata service to obtain the column names,\n             * column map and primary key\n             */\n            let metaData      = container->getShared(\"modelsMetadata\"),\n                modelInstance = create_instance_params(\n                    model,\n                    [\n                        null,\n                        container\n                    ]","sourceCodeStart":713,"sourceCodeEnd":749,"githubUrl":"https://github.com/phalcon/cphalcon/blob/b7419de9cd0a8a3f48441ead84c9f8415d463e25/phalcon/Mvc/Model/Query/Builder.zep#L713-L749","documentation":"Thrown in Builder::getPhql when conditions is a numeric primary-key shorthand but multiple models are set: the builder cannot decide which model's primary key the numeric condition applies to. The input at fault is a numeric conditions value combined with more than one model.","triggerScenarios":"Thrown at phalcon/Mvc/Model/Query/Builder.zep:731 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Use the numeric-conditions shorthand only with a single model in from().","With multiple models, write the condition explicitly: where('a.id = :id:')->bind(['id' => $id]).","Remove the numeric condition or reduce the builder to one model."],"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"}