{"record":{"id":"cb7166be5b719707","repo":"phalcon/cphalcon","slug":"check-expression-is-required","errorCode":null,"errorMessage":"CHECK expression is required","messagePattern":"CHECK expression is required","errorType":"exception","errorClass":"CheckExpressionRequired","httpStatus":null,"severity":"error","filePath":"phalcon/Db/Check.zep","lineNumber":72,"sourceCode":"\n    /**\n     * The CHECK constraint name. An empty string indicates an unnamed\n     * constraint - the dialect will emit the clause without a `CONSTRAINT`\n     * prefix in that case.\n     *\n     * @var string\n     */\n    protected name;\n\n    /**\n     * Phalcon\\Db\\Check constructor\n     */\n    public function __construct( string name,  array definition)\n    {\n        var expression;\n\n        if unlikely !fetch expression, definition[\"expression\"] {\n            throw new CheckExpressionRequired();\n        }\n\n        if unlikely typeof expression != \"string\" || expression === \"\" {\n            throw new InvalidCheckExpression();\n        }\n\n        let this->name       = name;\n        let this->expression = expression;\n    }\n\n    /**\n     * Returns the CHECK expression\n     */\n    public function getExpression() -> string\n    {\n        return this->expression;\n    }\n","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/phalcon/cphalcon/blob/b7419de9cd0a8a3f48441ead84c9f8415d463e25/phalcon/Db/Check.zep#L54-L90","documentation":"Phalcon\\Db\\Check models a CHECK constraint. Its constructor requires definition['expression'] - the raw SQL expression placed inside CHECK (...). Without that key the object cannot represent any constraint, so construction fails with CheckExpressionRequired before name or expression are assigned.","triggerScenarios":"new Check('chk_price', []) or a definition carrying only unrelated keys; typo'd keys ('expr', 'sql', 'condition'); constraint arrays built dynamically from config where the expression entry was never set.","commonSituations":"Schema builders converting config/annotations into Check objects; hand-written migrations where the expression line was forgotten; refactors renaming keys inconsistently between producer and consumer code.","solutions":["Add 'expression' => 'price >= 0' (any valid SQL boolean expression) to the definition array.","Validate the key before constructing when definitions come from external config.","Use the exact lowercase key 'expression'."],"exampleFix":"// before\n$check = new Check('chk_price', ['type' => 'check']); // throws CheckExpressionRequired\n\n// after\n$check = new Check('chk_price', ['expression' => 'price >= 0']);","handlingStrategy":"validation","validationCode":"if (!isset($definition['expression'])) {\n    throw new InvalidArgumentException('Check definition requires \"expression\"');\n}\n$check = new Check('chk_price', $definition);","typeGuard":"function checkDefinitionIsValid(array $definition): bool\n{\n    return isset($definition['expression'])\n        && is_string($definition['expression'])\n        && $definition['expression'] !== '';\n}","tryCatchPattern":null,"preventionTips":["Treat constraint definitions as typed value objects, not loose arrays.","Validate config-sourced definitions at load time, before DDL runs.","Wrap Check construction in a small factory so the key is set in exactly one place."],"tags":["check-constraint","schema-definition","phalcon-db"],"backgroundTag":"missing-required-array-key","analyzedSha":"b7419de9cd0a8a3f48441ead84c9f8415d463e25","analyzedAt":"2026-08-21T06:21:18.811Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}