{"record":{"id":"cb675894e7ed82cd","repo":"cakephp/cakephp","slug":"when-should-be-one-of-always-new-or-existing-the-passed","errorCode":null,"errorMessage":"When should be one of \"always\", \"new\" or \"existing\". The passed value `%s` is invalid.","messagePattern":"When should be one of \"always\", \"new\" or \"existing\"\\. The passed value `(.+?)` is invalid\\.","errorType":"exception","errorClass":"UnexpectedValueException","httpStatus":null,"severity":"error","filePath":"src/ORM/Behavior/TimestampBehavior.php","lineNumber":105,"sourceCode":"    public function handleEvent(EventInterface $event, EntityInterface $entity): void\n    {\n        $eventName = $event->getName();\n        $events = $this->_config['events'];\n\n        $new = $entity->isNew();\n        $refresh = $this->_config['refreshTimestamp'];\n\n        foreach ($events[$eventName] as $field => $when) {\n            if (!in_array($when, ['always', 'new', 'existing'], true)) {\n                throw new UnexpectedValueException(sprintf(\n                    'When should be one of \"always\", \"new\" or \"existing\". The passed value `%s` is invalid.',\n                    $when,\n                ));\n            }\n            if (\n                $when === 'always' ||\n                (\n                    $when === 'new' &&\n                    $new\n                ) ||\n                (\n                    $when === 'existing' &&\n                    !$new\n                )\n            ) {\n                $this->_updateField($entity, $field, $refresh);\n            }\n        }\n    }","sourceCodeStart":87,"sourceCodeEnd":123,"githubUrl":"https://github.com/cakephp/cakephp/blob/1128eba9b09f1946df684811350e26f2cef68fac/src/ORM/Behavior/TimestampBehavior.php#L87-L123","documentation":"TimestampBehavior::handleEvent() validates the behavior's 'when' configuration on each handled model event; only 'always', 'new' or 'existing' are meaningful modes for deciding when timestamps are refreshed. Any other value (usually a typo in the behavior config) raises UnexpectedValueException.","triggerScenarios":"Thrown at src/ORM/Behavior/TimestampBehavior.php:105 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Fix the behavior's `events` configuration so each field's `when` value is one of 'always', 'new' or 'existing'.","Remove the invalid entry or use the correct string, e.g. 'events' => ['Model.beforeSave' => ['modified' => 'always']]."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"1128eba9b09f1946df684811350e26f2cef68fac","analyzedAt":"2026-09-12T12:07:00.388Z","contentChangedAt":"2026-09-12T12:07:00.388Z","schemaVersion":2},"datasetVersion":"2026-09-19T12:17:13.211Z"}