{"id":"5e9e5620e1987226","repo":"drizzle-team/drizzle-orm","slug":"your-f-path-join-field-references-a-col-5e9e56","errorCode":null,"errorMessage":"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?","messagePattern":"Your \"(.+?)\" field references a column \"(.+?)\"\\.\"(.+?)\", but the table \"(.+?)\" is not part of the query! Did you forget to join it\\?","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"drizzle-orm/src/singlestore-core/dialect.ts","lineNumber":337,"sourceCode":"\t\t\t\t&& getTableName(f.field.table)\n\t\t\t\t\t!== (is(table, Subquery)\n\t\t\t\t\t\t? table._.alias\n\t\t\t\t\t\t/* : is(table, SingleStoreViewBase)\n\t\t\t\t\t\t? table[ViewBaseConfig].name */\n\t\t\t\t\t\t: is(table, SQL)\n\t\t\t\t\t\t? undefined\n\t\t\t\t\t\t: getTableName(table))\n\t\t\t\t&& !((table) =>\n\t\t\t\t\tjoins?.some(\n\t\t\t\t\t\t({ alias }) =>\n\t\t\t\t\t\t\talias\n\t\t\t\t\t\t\t\t=== (table[Table.Symbol.IsAlias]\n\t\t\t\t\t\t\t\t\t? getTableName(table)\n\t\t\t\t\t\t\t\t\t: table[Table.Symbol.BaseName]),\n\t\t\t\t\t))(f.field.table)\n\t\t\t) {\n\t\t\t\tconst tableName = getTableName(f.field.table);\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Your \"${\n\t\t\t\t\t\tf.path.join(\n\t\t\t\t\t\t\t'->',\n\t\t\t\t\t\t)\n\t\t\t\t\t}\" field references a column \"${tableName}\".\"${f.field.name}\", but the table \"${tableName}\" is not part of the query! Did you forget to join it?`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\tconst isSingleTable = !joins || joins.length === 0;\n\n\t\tconst withSql = this.buildWithCTE(withList);\n\n\t\tconst distinctSql = distinct ? sql` distinct` : undefined;\n\n\t\tconst selection = this.buildSelection(fieldsList, { isSingleTable });\n\n\t\tconst tableSql = (() => {","sourceCodeStart":319,"sourceCodeEnd":355,"githubUrl":"https://github.com/drizzle-team/drizzle-orm/blob/b7862528fd8fc39bc2653a6c18dad7c1f4e68d10/drizzle-orm/src/singlestore-core/dialect.ts#L319-L355","documentation":"Thrown in SingleStoreDialect.buildSelectQuery (dialect.ts:337) when iterating ordered selected fields: a referenced Column's underlying table is neither the FROM table nor present in the joins list. Drizzle cannot emit a valid SQL query that selects a column from a table that isn't in scope, so it aborts at SQL-build time with a message naming the offending table, column, and selection path.","triggerScenarios":"Calling db.select({ x: otherTable.col }).from(table) without a corresponding .leftJoin/.innerJoin on otherTable; referencing a joined table's column that was joined under a different alias than the one the column object carries; building a select with fieldsFlat referencing a subquery's outer column that isn't aliased to a joined table.","commonSituations":"Refactoring a query and deleting a join but forgetting to remove the now-orphaned column from the select list; aliasing a table with `.as('alias')` but selecting columns from the original (un-aliased) table object; copying a column reference from a different query's scope.","solutions":["Add the missing join for the referenced table (e.g. .leftJoin(otherTable, eq(table.id, otherTable.fk))).","If the table is already joined under an alias, select from the aliased instance (otherTableAlias.col), not the original table object.","Remove the column from the select list if it is not actually needed."],"exampleFix":"// before\nawait db.select({ id: users.id, petName: pets.name })\n  .from(users);\n// after\nawait db.select({ id: users.id, petName: pets.name })\n  .from(users)\n  .leftJoin(pets, eq(users.id, pets.ownerId));","handlingStrategy":"validation","validationCode":"import { getTableName } from 'drizzle-orm/table';\nfunction collectUsedTables(fromTable, joins = []) {\n  const names = new Set([getTableName(fromTable)]);\n  for (const j of joins) if (j.alias) names.add(j.alias);\n  return names;\n}\n// before executing, verify every selected column's table is in the used set\nfunction assertAllReferencedTablesJoined(selectFields, usedTables) {\n  for (const f of selectFields) {\n    if (f.path && f.field?.table) {\n      const t = getTableName(f.field.table);\n      if (!usedTables.has(t)) throw new Error(`Missing join for table ${t}`);\n    }\n  }\n}","typeGuard":"import { is, Column } from 'drizzle-orm';\nfunction columnTableIsInQuery(col, fromTable, joins = []) {\n  const allowed = new Set([getTableName(fromTable), ...joins.map(j => j.alias).filter(Boolean)]);\n  return is(col, Column) && allowed.has(getTableName(col.table));\n}","tryCatchPattern":"try { await q; } catch (e) { if (/is not part of the query/.test(e.message)) { /* add the missing join */ } throw e; }","preventionTips":["Always pair a column selection from table T with a join on T.","When aliasing via .as('x'), select columns from the aliased instance.","Lint for orphaned column references when removing a join."],"tags":["select","join","singlestore","query-builder","schema"],"analyzedSha":"b7862528fd8fc39bc2653a6c18dad7c1f4e68d10","analyzedAt":"2026-08-03T18:11:14.318Z","schemaVersion":2}