{"record":{"id":"2981056b1552bce0","repo":"n8n-io/n8n","slug":"cannot-find-relation-propertypath-wrong-relati","errorCode":null,"errorMessage":"Cannot find relation ${propertyPath}. Wrong relation specified for @RelationCount decorator.","messagePattern":"Cannot find relation (.+?)\\. Wrong relation specified for @RelationCount decorator\\.","errorType":"exception","errorClass":"TypeORMError","httpStatus":null,"severity":"error","filePath":"packages/@n8n/typeorm/src/metadata/RelationCountMetadata.ts","lineNumber":81,"sourceCode":"\t\tthis.queryBuilderFactory = options.args.queryBuilderFactory;\n\t}\n\n\t// ---------------------------------------------------------------------\n\t// Public Builder Methods\n\t// ---------------------------------------------------------------------\n\n\t/**\n\t * Builds some depend relation count metadata properties.\n\t * This builder method should be used only after entity metadata, its properties map and all relations are build.\n\t */\n\tbuild() {\n\t\tconst propertyPath =\n\t\t\ttypeof this.relationNameOrFactory === 'function'\n\t\t\t\t? this.relationNameOrFactory(this.entityMetadata.propertiesMap)\n\t\t\t\t: this.relationNameOrFactory;\n\t\tconst relation = this.entityMetadata.findRelationWithPropertyPath(propertyPath);\n\t\tif (!relation)\n\t\t\tthrow new TypeORMError(\n\t\t\t\t`Cannot find relation ${propertyPath}. Wrong relation specified for @RelationCount decorator.`,\n\t\t\t);\n\n\t\tthis.relation = relation;\n\t}\n}\n","sourceCodeStart":63,"sourceCodeEnd":88,"githubUrl":"https://github.com/n8n-io/n8n/blob/5ac6606e81f67bb9534255570cd4e86fd8101eee/packages/@n8n/typeorm/src/metadata/RelationCountMetadata.ts#L63-L88","documentation":"Thrown by RelationCountMetadata.build when the relation name or factory passed to @RelationCount cannot be resolved via findRelationWithPropertyPath on the entity. The decorator stores either a string or a (propertiesMap) => string function; build() resolves it and throws if no relation metadata matches.","triggerScenarios":"Decorating a property with @RelationCount(() => Entity, 'nonExistent') or @RelationCount(() => Entity, (p) => p.nonExistent) where the named path is not a defined relation on the same entity.","commonSituations":"Renaming the counted relation without updating the @RelationCount argument; pointing @RelationCount at a ManyToOne/OneToOne (also blocked separately) or at a plain column; refactor that moved the relation to another entity.","solutions":["Verify the relation name/factory points to an existing @OneToMany or @ManyToMany relation on the same entity.","After renaming the underlying relation, update the @RelationCount string/factory in lockstep.","If the relation was removed, delete the @RelationCount property entirely."],"exampleFix":"// before\n@RelationCount(() => Post, 'commnts') // typo\ncommentsCount: number;\n\n// after\n@RelationCount(() => Post, 'comments')\ncommentsCount: number;","handlingStrategy":"validation","validationCode":"function validateRelationCounts(dataSource: DataSource): string[] {\n  const problems: string[] = [];\n  for (const meta of dataSource.entityMetadatas) {\n    const relationPaths = new Set(meta.relations.map((r) => r.propertyPath));\n    for (const rc of meta.relationCounts) {\n      const target =\n        typeof rc.relationNameOrFactory === 'function'\n          ? rc.relationNameOrFactory(meta.propertiesMap)\n          : rc.relationNameOrFactory;\n      if (!relationPaths.has(target)) {\n        problems.push(`${meta.targetName}.@RelationCount -> missing relation '${target}'`);\n      }\n    }\n  }\n  return problems;\n}","typeGuard":null,"tryCatchPattern":"try {\n  await dataSource.initialize();\n} catch (err) {\n  if (err.message.includes('Wrong relation specified for @RelationCount')) {\n    // extract propertyPath and fix the decorator\n  }\n  throw err;\n}","preventionTips":["When renaming or removing a relation, grep for @RelationCount referencing its name.","Run the post-init validator above in CI so misconfigured RelationCounts fail early.","Keep relation names in a shared const so the decorator and its count reference one symbol."],"tags":["relation-count","relation","metadata","startup"],"backgroundTag":null,"analyzedSha":"5ac6606e81f67bb9534255570cd4e86fd8101eee","analyzedAt":"2026-08-12T05:26:35.080Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}