hcengineering/platform · error

association not found for ${assocId}

Error message

association not found for ${assocId}

What it means

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.

Source

Thrown at plugins/view-resources/src/utils.ts:657

    throw new Error('invalid relation key ' + key.key)
  }

  // Find the last association segment
  let lastAssocIndex = -1
  for (let i = 0; i < parts.length; i++) {
    if (parts[i] === '$associations' && i + 1 < parts.length) {
      lastAssocIndex = i
    }
  }
  if (lastAssocIndex === -1) {
    throw new Error('invalid relation key ' + key.key)
  }

  const fragments = parts[lastAssocIndex + 1].split('_')
  const assocId = fragments[0] as Ref<Association>
  const assoc = client.getModel().findObject(assocId)
  if (assoc === undefined) {
    throw new Error('association not found for ' + assocId)
  }
  const _class = fragments[1] === 'a' ? assoc.classA : assoc.classB
  const name = fragments[1] === 'a' ? assoc.nameA : assoc.nameB

  const hierarchy = client.getHierarchy()

  // Check if there are sub-field parts after the last association segment
  const subFieldParts = parts.slice(lastAssocIndex + 2)
  if (subFieldParts.length > 0) {
    // Sub-field key: resolve attribute presenter for the specific field
    const attrName = subFieldParts.join('.')
    try {
      const attribute = hierarchy.getAttribute(_class, attrName)
      const { attrClass, category } = getAttributePresenterClass(hierarchy, attribute.type)
      const presenterRef = findAttributePresenter(client, _class, attrName)
      if (presenterRef !== undefined) {
        const presenter = await getResource(presenterRef)
        return {

View on GitHub (pinned to 63e28dc964)

Solutions

  1. Re-derive the association Ref from the current model and rebuild the key
  2. Verify the association exists in the connected workspace's model
  3. Update serialized views/keys after model migrations that removed associations

Example fix

// before
{ key: `space.$associations.deletedAssocId_a` }
// after
const assoc = /* pick from client.getModel() */
{ key: `space.$associations.${assoc._id}_a` }
Defensive patterns

Strategy: validation

Validate before calling

const assocId = key.split('$associations.')[1]?.split('_')[0]
if (assocId && client.getModel().findObject(assocId as Ref<Association>) === undefined) {
  throw new Error('association missing from model: ' + assocId)
}

Type guard

function assocExists(client: Client, key: string): boolean {
  const id = key.split('$associations.')[1]?.split('_')[0]
  return id !== undefined && client.getModel().findObject(id as Ref<Association>) !== undefined
}

Try / catch

try {
  return await model(client, _class, [{ key }])
} catch (err) {
  if (String(err.message).startsWith('association not found')) {
    console.warn('stale association ref, rebuilding key'); return []
  }
  throw err
}

Prevention

When it happens

Trigger: 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.

Common situations: Hard-coding association ids captured from another environment; association removed in a newer data/model version; copy-pasting ids across dev/prod databases.

Related errors


AI-assisted analysis of hcengineering/platform@63e28dc964 (2026-08-29). Data as JSON: /api/errors/a615d326bbeb3fdf. Report an issue: GitHub.