{"record":{"id":"e88850bcfb1b50fc","repo":"nocobase/nocobase","slug":"the-record-does-not-exist","errorCode":null,"errorMessage":"The record does not exist","messagePattern":"The record does not exist","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/core/database/src/relation-repository/single-relation-repository.ts","lineNumber":99,"sourceCode":"      transaction,\n    });\n\n    return true;\n  }\n\n  @transaction()\n  @injectTargetCollection\n  async update(options: UpdateOptions): Promise<any> {\n    const transaction = await this.getTransaction(options);\n\n    const target = await this.find({\n      transaction,\n      // @ts-ignore\n      targetCollection: options.targetCollection,\n    });\n\n    if (!target) {\n      throw new Error('The record does not exist');\n    }\n\n    await updateModelByValues(target, options?.values, {\n      ...options,\n      transaction,\n    });\n\n    if (options.hooks !== false) {\n      await this.db.emitAsync(`${this.targetCollection.name}.afterUpdateWithAssociations`, target, {\n        ...options,\n        transaction,\n      });\n      const eventName = `${this.targetCollection.name}.afterSaveWithAssociations`;\n      await this.db.emitAsync(eventName, target, { ...options, transaction });\n    }\n\n    return target;\n  }","sourceCodeStart":81,"sourceCodeEnd":117,"githubUrl":"https://github.com/nocobase/nocobase/blob/fa42722fefe44265490dff2c27d79e2882bce4fa/packages/core/database/src/relation-repository/single-relation-repository.ts#L81-L117","documentation":"SingleRelationRepository.update first fetches the related target record by the given filter/targetCollection. If no matching record exists, it throws 'The record does not exist' rather than silently returning. The association target row identified by your filter/query could not be loaded before applying values.","triggerScenarios":"Calling singleRelationRepository.update({ filterByTk: id, values }) (or via relation field update) where the related record with that tk was deleted, never existed, or the filter matches nothing; wrong targetCollection option passed.","commonSituations":"Stale UI referencing a deleted record; race condition where the record was removed between listing and updating; using the wrong primary key value or wrong collection name; multi-tenant/filter scoping hiding the record.","solutions":["Verify the record exists with a findOne/filter call using the same tk/filter before updating","Correct the filterByTk / filter value or targetCollection option","Handle the deleted-record case gracefully in the caller (create instead, or surface a 404)"],"exampleFix":"// before\nawait repo.update({ filterByTk: id, values }); // throws if deleted\n// after\nconst exists = await repo.findOne({ filterByTk: id });\nif (!exists) throw new NotFoundError(`Record ${id} not found`);\nawait repo.update({ filterByTk: id, values });","handlingStrategy":"try-catch","validationCode":"const exists = await singleRepo.findOne({ filterByTk: id });\nif (!exists) throw new NotFoundError(`Related record ${id} not found`);","typeGuard":"const hasTarget = async (repo, opts) => (await repo.findOne(opts)) !== null;","tryCatchPattern":"try { await singleRepo.update({ filterByTk: id, values }); } catch (e) { if (e.message === 'The record does not exist') { throw new NotFoundError(id); } throw e; }","preventionTips":["Check record existence before relation updates","Refresh stale IDs from the client after deletes","Pass correct targetCollection option"],"tags":["repository","relations","record-not-found"],"backgroundTag":"record-not-found","analyzedSha":"fa42722fefe44265490dff2c27d79e2882bce4fa","analyzedAt":"2026-09-01T00:54:31.202Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}