n8n-io/n8n · error · TypeORMError
Cannot find relation ${propertyPath}. Wrong relation specifi
Error message
Cannot find relation ${propertyPath}. Wrong relation specified for @RelationCount decorator. What it means
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.
Source
Thrown at packages/@n8n/typeorm/src/metadata/RelationCountMetadata.ts:81
this.queryBuilderFactory = options.args.queryBuilderFactory;
}
// ---------------------------------------------------------------------
// Public Builder Methods
// ---------------------------------------------------------------------
/**
* Builds some depend relation count metadata properties.
* This builder method should be used only after entity metadata, its properties map and all relations are build.
*/
build() {
const propertyPath =
typeof this.relationNameOrFactory === 'function'
? this.relationNameOrFactory(this.entityMetadata.propertiesMap)
: this.relationNameOrFactory;
const relation = this.entityMetadata.findRelationWithPropertyPath(propertyPath);
if (!relation)
throw new TypeORMError(
`Cannot find relation ${propertyPath}. Wrong relation specified for @RelationCount decorator.`,
);
this.relation = relation;
}
}
View on GitHub (pinned to 5ac6606e81)
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.
Example fix
// before @RelationCount(() => Post, 'commnts') // typo commentsCount: number; // after @RelationCount(() => Post, 'comments') commentsCount: number;
Defensive patterns
Strategy: validation
Validate before calling
function validateRelationCounts(dataSource: DataSource): string[] {
const problems: string[] = [];
for (const meta of dataSource.entityMetadatas) {
const relationPaths = new Set(meta.relations.map((r) => r.propertyPath));
for (const rc of meta.relationCounts) {
const target =
typeof rc.relationNameOrFactory === 'function'
? rc.relationNameOrFactory(meta.propertiesMap)
: rc.relationNameOrFactory;
if (!relationPaths.has(target)) {
problems.push(`${meta.targetName}.@RelationCount -> missing relation '${target}'`);
}
}
}
return problems;
} Try / catch
try {
await dataSource.initialize();
} catch (err) {
if (err.message.includes('Wrong relation specified for @RelationCount')) {
// extract propertyPath and fix the decorator
}
throw err;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Cannot find relation ${propertyPath}. Wrong relation specifi
- Relation count can not be implemented on ManyToOne or OneToO
- Index ${indexName}contains column that is missing in the ent
- Unique constraint ${indexName}contains column that is missin
- Entity metadata for ${entityMetadata.name}#${relation.proper
AI-assisted analysis of n8n-io/n8n@5ac6606e81 (2026-08-12).
Data as JSON: /api/errors/2981056b1552bce0.
Report an issue: GitHub.