{"record":{"id":"55d0046b16816f88","repo":"passbolt/passbolt_api","slug":"associatedrecordexists","errorCode":"AssociatedRecordExists","errorMessage":"$errors['id']['AssociatedRecordExists'] (dynamic validation error message)","messagePattern":"\\$errors\\['id'\\]\\['AssociatedRecordExists'\\] \\(dynamic validation error message\\)","errorType":"http","errorClass":"NotFoundException","httpStatus":404,"severity":"error","filePath":"plugins/PassboltEe/DirectorySync/src/Controller/DirectoryIgnoreController.php","lineNumber":134,"sourceCode":"     * @return void\n     */\n    public function add(string $foreignModel, string $foreignKey): void\n    {\n        if ($this->User->role() !== Role::ADMIN) {\n            throw new ForbiddenException(__('You are not authorized to access that location.'));\n        }\n        $this->assertDirectoryEnabled();\n        $foreignModel = $this->normalizeForeignModel($foreignModel);\n        if (!Validation::inList($foreignModel, ['Groups', 'Users', 'DirectoryEntries'])) {\n            throw new BadRequestException(__('The record model is not valid.'));\n        }\n\n        try {\n            $ignored = $this->DirectoryIgnore->createOrFail($foreignModel, $foreignKey);\n        } catch (ValidationException $exception) {\n            $errors = $exception->getEntity()->getErrors();\n            if (isset($errors['id']['AssociatedRecordExists'])) {\n                throw new NotFoundException($errors['id']['AssociatedRecordExists']);\n            }\n            throw $exception;\n        }\n        $this->success(__('The record will be ignored in the next directory synchronization.'), $ignored);\n    }\n\n    /**\n     * Delete\n     *\n     * @param string $foreignModel foreign model\n     * @param string $foreignKey foreign key\n     * @return void\n     */\n    public function delete(string $foreignModel, string $foreignKey): void\n    {\n        if ($this->User->role() !== Role::ADMIN) {\n            throw new ForbiddenException(__('You are not authorized to access that location.'));\n        }","sourceCodeStart":116,"sourceCodeEnd":152,"githubUrl":"https://github.com/passbolt/passbolt_api/blob/31c1bbc10f32808a607fa9bd81891e898779c0bc/plugins/PassboltEe/DirectorySync/src/Controller/DirectoryIgnoreController.php#L116-L152","documentation":"Raised in add() when DirectoryIgnore->createOrFail() fails validation with the 'AssociatedRecordExists' rule on the id field. It means the referenced user/group/directory-entry does not exist in the main application tables, so an ignore row cannot be created; the controller converts this validation error into an HTTP 404 NotFoundException carrying the dynamic validation message.","triggerScenarios":"POST /directoryignore/users/{uuid} where the uuid does not match any existing Users row (same for Groups/DirectoryEntries), e.g. a deleted entity id or a fabricated uuid.","commonSituations":"Syncing stale directory data whose linked passbolt user was deleted; ids taken from an old export; mixing uuids across environments (staging vs production); typos when hand-crafting requests.","solutions":["Verify the entity exists first (GET /users/{uuid}, /groups/{uuid}) before marking it ignored","Refresh the id from a current listing instead of a cached/stale source","Check you are calling the correct environment's API for that uuid","Handle 404 in the client as 'associated record missing' and resync directory entries"],"exampleFix":"// before: post with deleted user id → 404\n$api->ignore('users', $deletedUserId);\n// after: guard first\nif ($api->userExists($userId)) { $api->ignore('users', $userId); }","handlingStrategy":"validation","validationCode":"try {\n    $api->get(\"/{$model}/{$id}.json\");\n} catch (NotFoundException $e) {\n    throw new \\RuntimeException(\"cannot ignore $model $id: record does not exist\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    $api->post(\"/directoryignore/{$model}/{$id}.json\");\n} catch (NotFoundException $e) {\n    // 404 with AssociatedRecordExists: referenced user/group/entry not found\n    // resync directory entries or fix the uuid\n}","preventionTips":["Verify the target entity exists before marking it ignored","Keep ids fresh from live listings, not cached exports","Watch for cross-environment uuid mix-ups"],"tags":["not-found","validation","foreign-key","directory-sync"],"backgroundTag":"entity-not-found","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"}