n8n-io/n8n · error · TypeORMError

Cannot get junction table for join without relation.

Error message

Cannot get junction table for join without relation.

What it means

JoinAttribute.junctionAlias getter throws when this.relation is falsy. Junction tables (the join table for @ManyToMany) only exist for relation-backed joins; a raw table or subquery join has no junction. Accessing junctionAlias on such a join is a programming error — the caller assumed a many-to-many relation where none exists.

Source

Thrown at packages/@n8n/typeorm/src/query-builder/JoinAttribute.ts:219

		/*if (typeof this.entityOrProperty === "string") { // entityOrProperty is a custom table

            // first try to find entity with such name, this is needed when entity does not have a target class,
            // and its target is a string name (scenario when plain old javascript is used or entity schema is loaded from files)
            const metadata = this.connection.entityMetadatas.find(metadata => metadata.name === this.entityOrProperty);
            if (metadata)
                return metadata;

            // check if we have entity with such table name, and use its metadata if found
            return this.connection.entityMetadatas.find(metadata => metadata.tableName === this.entityOrProperty);
        }*/
	}

	/**
	 * Generates alias of junction table, whose ids we get.
	 */
	get junctionAlias(): string {
		if (!this.relation) {
			throw new TypeORMError(`Cannot get junction table for join without relation.`);
		}
		if (typeof this.entityOrProperty !== 'string') {
			throw new TypeORMError(`Junction property is not defined.`);
		}

		const aliasProperty = this.entityOrProperty.substr(0, this.entityOrProperty.indexOf('.'));

		if (this.relation.isOwning) {
			return DriverUtils.buildAlias(
				this.connection.driver,
				undefined,
				aliasProperty,
				this.alias.name,
			);
		} else {
			return DriverUtils.buildAlias(
				this.connection.driver,
				undefined,

View on GitHub (pinned to 5ac6606e81)

Solutions

  1. Ensure the @ManyToMany relation has a @JoinTable decorator so metadata resolution succeeds.
  2. Avoid calling relation-dependent query-builder APIs on raw (non-relation) joins.
  3. Verify the join target is a relation (joinAttribute.relation is truthy) before the code path that reads junctionAlias.
  4. Re-check entity registration in the DataSource so relation metadata is populated.

Example fix

// before — missing @JoinTable causes relation to resolve undefined
@Entity()
class Team {
  @ManyToMany(() => User)
  members: User[]; // junctionAlias access later throws
}

// after
@Entity()
class Team {
  @ManyToMany(() => User)
  @JoinTable()
  members: User[];
}
Defensive patterns

Strategy: type-guard

Validate before calling

function isManyToManyRelation(rel: import('../metadata/RelationMetadata').RelationMetadata | undefined): boolean {
  return !!rel && rel.relationType === 'many-to-many';
}
const rel = entityMetadata.findRelationWithPropertyPath('members');
if (!isManyToManyRelation(rel)) throw new Error('junction alias requires a many-to-many relation');

Type guard

function hasRelation(attr: { relation: unknown }): attr is { relation: import('../metadata/RelationMetadata').RelationMetadata } {
  return attr.relation != null;
}

Prevention

When it happens

Trigger: Internal TypeORM code path (e.g. relation loader, many-to-many persistence) calls joinAttribute.junctionAlias on a JoinAttribute whose relation getter returned undefined because the join target is not a relation. Reproduced by attempting many-to-many operations on a join that was built from a raw table or whose relation metadata failed to resolve.

Common situations: Mixing raw joins with relation-based many-to-many persistence on the same query. Entity misconfiguration where a @ManyToMany is missing the @JoinTable so relation resolution yields undefined. Custom query-builder extensions that assume junction presence.

Related errors


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