{"record":{"id":"4f4e9cebba0aa33c","repo":"nocobase/nocobase","slug":"unsupported-association-or-no-usable-accessor-on","errorCode":null,"errorMessage":"Unsupported association or no usable accessor on ${this.repository['association']}","messagePattern":"Unsupported association or no usable accessor on (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/plugins/@nocobase/plugin-action-import/src/server/services/xlsx-importer.ts","lineNumber":613,"sourceCode":"      throw new Error('Missing accessors or source model.');\n    }\n\n    if ((accessors as MultiAssociationAccessors).addMultiple) {\n      // For hasMany, belongsToMany\n      await sourceModel[(accessors as MultiAssociationAccessors).addMultiple](targets, options);\n    } else if ((accessors as MultiAssociationAccessors).add) {\n      // Also works for hasMany / belongsToMany\n      await Promise.all(\n        targets.map((target) => sourceModel[(accessors as MultiAssociationAccessors).add](target, options)),\n      );\n    } else if (accessors.set) {\n      // set accessor（hasOne, belongsTo）\n      if (targets.length > 1) {\n        throw new Error('Cannot associate multiple records to a single-valued relation.');\n      }\n      await sourceModel[accessors.set](targets[0], options);\n    } else {\n      throw new Error(`Unsupported association or no usable accessor on ${this.repository['association']}`);\n    }\n  }\n\n  renderErrorMessage(error) {\n    let message = error.message;\n    if (error.parent) {\n      message += `: ${error.parent.message}`;\n    }\n\n    return message;\n  }\n  trimString(str: string) {\n    if (typeof str === 'string') {\n      return str.trim();\n    }\n\n    return str;\n  }","sourceCodeStart":595,"sourceCodeEnd":631,"githubUrl":"https://github.com/nocobase/nocobase/blob/fa42722fefe44265490dff2c27d79e2882bce4fa/packages/plugins/@nocobase/plugin-action-import/src/server/services/xlsx-importer.ts#L595-L631","documentation":"Plain Error thrown by associateRecords as the fallback branch: the repository's association exposes none of the expected accessors (addMultiple, add, set). The message interpolates `this.repository['association']` so the unsupported association object is shown. It indicates the association type/accessors are not what the importer expects.","triggerScenarios":"Repository association is undefined or of a type without standard Sequelize accessors — e.g. repository not an association repository, custom repository overriding accessors(), or association misconfigured so neither add/addMultiple nor set exists.","commonSituations":"Custom relation/repository implementations lacking Sequelize accessor methods; importing through the wrong repository path; datasource plugin version mismatch where accessors() shape changed.","solutions":["Verify the import runs on a RelationRepository for a standard relation type (hasMany/belongsToMany/hasOne/belongsTo).","Read the interpolated association value in the message to see which association was actually resolved.","Fix the relation configuration so Sequelize generates add/set accessors (association must be defined on the model).","Update/align datasource plugin versions if accessors() API changed."],"exampleFix":"// before\nthrow new Error(`Unsupported association or no usable accessor on ${this.repository['association']}`); // association undefined\n// after\n// configure the relation first:\ndb.collection({ name: 'users', fields: [{ type: 'belongsTo', name: 'org', target: 'orgs' }] });","handlingStrategy":"type-guard","validationCode":"const assoc = (repository as any)?.['association'];\nif (!assoc) throw new Error('Repository is not an association repository');","typeGuard":"function isRelationRepository(r: any): r is RelationRepository {\n  return r instanceof RelationRepository && !!r['association'];\n}","tryCatchPattern":"try {\n  await repository.performInsert({ values }, ctx);\n} catch (e) {\n  if (e.message.startsWith('Unsupported association')) {\n    console.error('Resolved association:', e.message); // inspect and fix relation config\n  }\n  throw e;\n}","preventionTips":["Use standard relation types (hasMany/belongsToMany/hasOne/belongsTo).","Import via RelationRepository obtained from collection.getRepository(relationName).","Keep datasource/sequelize plugins in sync to avoid accessor API drift.","Log repository.constructor.name and accessors() when debugging custom repositories."],"tags":["import","association","repository","sequelize"],"backgroundTag":"unsupported-association-type","analyzedSha":"fa42722fefe44265490dff2c27d79e2882bce4fa","analyzedAt":"2026-09-01T00:54:31.202Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}