{"record":{"id":"cc52233c6dc4326c","repo":"passbolt/passbolt_api","slug":"could-not-validate-folder-relation-data","errorCode":null,"errorMessage":"Could not validate folder relation data.","messagePattern":"Could not validate folder relation data\\.","errorType":"validation","errorClass":"App\\Error\\Exception\\ValidationException","httpStatus":400,"severity":"error","filePath":"plugins/PassboltCe/Folders/src/Service/FoldersRelations/FoldersRelationsCreateService.php","lineNumber":89,"sourceCode":"            'user_id' => true,\n            'folder_parent_id' => true,\n        ];\n\n        return $this->foldersRelationsTable->newEntity($folderRelationData, ['accessibleFields' => $accessibleFields]);\n    }\n\n    /**\n     * Handle folder relation validation errors.\n     *\n     * @param \\Passbolt\\Folders\\Model\\Entity\\FoldersRelation $folderRelation The folder relation\n     * @return void\n     */\n    private function handleFolderRelationValidationErrors(FoldersRelation $folderRelation): void\n    {\n        $errors = $folderRelation->getErrors();\n        if (!empty($errors)) {\n            $msg = __('Could not validate folder relation data.');\n            throw new ValidationException($msg, $folderRelation, $this->foldersRelationsTable);\n        }\n    }\n}\n","sourceCodeStart":71,"sourceCodeEnd":93,"githubUrl":"https://github.com/passbolt/passbolt_api/blob/31c1bbc10f32808a607fa9bd81891e898779c0bc/plugins/PassboltCe/Folders/src/Service/FoldersRelations/FoldersRelationsCreateService.php#L71-L93","documentation":"A ValidationException raised by FoldersRelationsCreateService::handleFolderRelationValidationErrors when a new FoldersRelation entity fails model validation during create. The folder relation (linking a folder/resource to its parent in a user tree) did not pass FoldersRelationsTable rules, and the exception carries the entity and table for detailed errors.","triggerScenarios":"Folder or item creation/move flows calling FoldersRelationsCreateService::create with invalid relation data: unknown foreign model value (must be 'Folder' or 'Resource'), invalid user_id/foreign_id UUIDs, or a relation violating uniqueness/table rules.","commonSituations":"Plugins or scripts creating folder relations directly with wrong foreign_model strings, non-existent folder/resource ids, or duplicate relations for the same user; version mismatches where the enum of allowed foreign models changed.","solutions":["Read the entity errors in the 400 response to identify the failing field (usually foreign_model, foreign_id, or user_id).","Use only valid foreign_model values ('Folder', 'Resource') and valid UUIDs for foreign_id and user_id.","Ensure the referenced folder/resource actually exists and belongs to the same user tree context.","Check for duplicates: a user should not already have an identical relation row."],"exampleFix":"// before\n{\"foreign_model\":\"folder\", \"foreign_id\":\"abc\"} // invalid: lowercase model, non-uuid id\n// after\n{\"foreign_model\":\"Folder\", \"foreign_id\":\"8e3874ae-4b40-590b-b236-2c2648d88a3b\"}","handlingStrategy":"validation","validationCode":"const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;\nfunction validateFolderRelation(rel) {\n  return ['Folder', 'Resource'].includes(rel.foreign_model)\n    && UUID.test(rel.foreign_id ?? '')\n    && UUID.test(rel.user_id ?? '');\n}","typeGuard":null,"tryCatchPattern":"try {\n  await folderRelationsApi.create(rel);\n} catch (e) {\n  if (e.response?.status === 400 && e.response.data?.errors) {\n    console.error('Relation validation failed:', e.response.data.errors);\n  }\n  throw e;\n}","preventionTips":["Use exact foreign_model values: 'Folder' or 'Resource'.","Validate all ids as UUIDs and confirm the referenced entities exist.","Prevent duplicate relation rows per user/item.","Rely on high-level folder/resource APIs instead of creating relations directly."],"tags":["validation","folders-relations","entity-validation"],"backgroundTag":"schema-validation-failed","analyzedSha":"31c1bbc10f32808a607fa9bd81891e898779c0bc","analyzedAt":"2026-09-17T00:04:38.960Z","contentChangedAt":"2026-09-17T00:04:38.960Z","schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}