{"record":{"id":"a615d326bbeb3fdf","repo":"hcengineering/platform","slug":"association-not-found-for-associd","errorCode":null,"errorMessage":"association not found for ${assocId}","messagePattern":"association not found for (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"plugins/view-resources/src/utils.ts","lineNumber":657,"sourceCode":"    throw new Error('invalid relation key ' + key.key)\n  }\n\n  // Find the last association segment\n  let lastAssocIndex = -1\n  for (let i = 0; i < parts.length; i++) {\n    if (parts[i] === '$associations' && i + 1 < parts.length) {\n      lastAssocIndex = i\n    }\n  }\n  if (lastAssocIndex === -1) {\n    throw new Error('invalid relation key ' + key.key)\n  }\n\n  const fragments = parts[lastAssocIndex + 1].split('_')\n  const assocId = fragments[0] as Ref<Association>\n  const assoc = client.getModel().findObject(assocId)\n  if (assoc === undefined) {\n    throw new Error('association not found for ' + assocId)\n  }\n  const _class = fragments[1] === 'a' ? assoc.classA : assoc.classB\n  const name = fragments[1] === 'a' ? assoc.nameA : assoc.nameB\n\n  const hierarchy = client.getHierarchy()\n\n  // Check if there are sub-field parts after the last association segment\n  const subFieldParts = parts.slice(lastAssocIndex + 2)\n  if (subFieldParts.length > 0) {\n    // Sub-field key: resolve attribute presenter for the specific field\n    const attrName = subFieldParts.join('.')\n    try {\n      const attribute = hierarchy.getAttribute(_class, attrName)\n      const { attrClass, category } = getAttributePresenterClass(hierarchy, attribute.type)\n      const presenterRef = findAttributePresenter(client, _class, attrName)\n      if (presenterRef !== undefined) {\n        const presenter = await getResource(presenterRef)\n        return {","sourceCodeStart":639,"sourceCodeEnd":675,"githubUrl":"https://github.com/hcengineering/platform/blob/63e28dc96483967b2fc21c881b3f1023c1de7718/plugins/view-resources/src/utils.ts#L639-L675","documentation":"The key's association descriptor starts with an association object Ref; the code looks it up via client.getModel().findObject(assocId). If no such object exists in the model, the association cannot be resolved and the function throws.","triggerScenarios":"Key contains '$associations.<assocId>_a' where assocId refers to an Association doc that is not in the client's model — deleted association, wrong workspace/PROJECT, stale serialized key, or mistyped id.","commonSituations":"Hard-coding association ids captured from another environment; association removed in a newer data/model version; copy-pasting ids across dev/prod databases.","solutions":["Re-derive the association Ref from the current model and rebuild the key","Verify the association exists in the connected workspace's model","Update serialized views/keys after model migrations that removed associations"],"exampleFix":"// before\n{ key: `space.$associations.deletedAssocId_a` }\n// after\nconst assoc = /* pick from client.getModel() */\n{ key: `space.$associations.${assoc._id}_a` }","handlingStrategy":"validation","validationCode":"const assocId = key.split('$associations.')[1]?.split('_')[0]\nif (assocId && client.getModel().findObject(assocId as Ref<Association>) === undefined) {\n  throw new Error('association missing from model: ' + assocId)\n}","typeGuard":"function assocExists(client: Client, key: string): boolean {\n  const id = key.split('$associations.')[1]?.split('_')[0]\n  return id !== undefined && client.getModel().findObject(id as Ref<Association>) !== undefined\n}","tryCatchPattern":"try {\n  return await model(client, _class, [{ key }])\n} catch (err) {\n  if (String(err.message).startsWith('association not found')) {\n    console.warn('stale association ref, rebuilding key'); return []\n  }\n  throw err\n}","preventionTips":["Never hard-code association Refs; resolve them from client.getModel() at runtime","Rebuild keys after model migrations or workspace switches","Check association existence in the target workspace before building views"],"tags":["association","model-lookup","stale-reference","view-model"],"backgroundTag":"model-object-not-found","analyzedSha":"63e28dc96483967b2fc21c881b3f1023c1de7718","analyzedAt":"2026-08-29T15:21:27.377Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}