drizzle-team/drizzle-orm · error · Error

Your "${f.path.join('->')}" field references a column "${tab

Error message

Your "${f.path.join('->')}" field references a column "${tableName}"."${f.field.name}", but the table "${tableName}" is not part of the query! Did you forget to join it?

What it means

Error "Your "${f.path.join('->')}" field references a column "${tableName}"."${f.field.name}", but the table "${tableName}" is not part of the query! Did you forget to join it?" thrown in drizzle-team/drizzle-orm.

Source

Thrown at drizzle-orm/src/gel-core/dialect.ts:372

		const fieldsList = fieldsFlat ?? orderSelectedFields<GelColumn>(fields);
		for (const f of fieldsList) {
			if (
				is(f.field, Column)
				&& getTableName(f.field.table)
					!== (is(table, Subquery)
						? table._.alias
						: is(table, GelViewBase)
						? table[ViewBaseConfig].name
						: is(table, SQL)
						? undefined
						: getTableName(table))
				&& !((table) =>
					joins?.some(({ alias }) =>
						alias === (table[Table.Symbol.IsAlias] ? getTableName(table) : table[Table.Symbol.BaseName])
					))(f.field.table)
			) {
				const tableName = getTableName(f.field.table);
				throw new Error(
					`Your "${
						f.path.join('->')
					}" field references a column "${tableName}"."${f.field.name}", but the table "${tableName}" is not part of the query! Did you forget to join it?`,
				);
			}
		}

		const isSingleTable = !joins || joins.length === 0;

		const withSql = this.buildWithCTE(withList);

		let distinctSql: SQL | undefined;
		if (distinct) {
			distinctSql = distinct === true ? sql` distinct` : sql` distinct on (${sql.join(distinct.on, sql`, `)})`;
		}

		const selection = this.buildSelection(fieldsList, { isSingleTable });

View on GitHub (pinned to b7862528fd)

Solutions

  1. Join the referenced table into the query (e.g. .leftJoin(table, ...) or include it via "with") before selecting its fields.
  2. Check that the table alias used in the field path matches the alias used in the join.

When it happens

Trigger: A relational query (Gel dialect) selects a field with a path that walks into a table that was never joined into the query.

Common situations: Using 'with'/'columns' extras referencing related tables without joining; typos in relation field paths; removed join leaving stale selection.


AI-assisted analysis of drizzle-team/drizzle-orm@b7862528fd (2026-08-03). Data as JSON: /data/errors/cf8cd90ddd822032.json. Report an issue: GitHub.