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

  1. Verify the relation name/factory points to an existing @OneToMany or @ManyToMany relation on the same entity.
  2. After renaming the underlying relation, update the @RelationCount string/factory in lockstep.
  3. 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 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


AI-assisted analysis of n8n-io/n8n@5ac6606e81 (2026-08-12). Data as JSON: /api/errors/2981056b1552bce0. Report an issue: GitHub.