{"id":"b40d2537b9b19181","repo":"drizzle-team/drizzle-orm","slug":"your-f-path-join-field-references-a-col-b40d25","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/sqlite-core/dialect.ts","lineNumber":381,"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, SQLiteViewBase)\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 = this.buildFromTable(table);","sourceCodeStart":363,"sourceCodeEnd":399,"githubUrl":"https://github.com/drizzle-team/drizzle-orm/blob/b7862528fd8fc39bc2653a6c18dad7c1f4e68d10/drizzle-orm/src/sqlite-core/dialect.ts#L363-L399","documentation":"Thrown while building a SQLite SELECT (dialect.ts:381) when a field in the selection list references a column belonging to a table that is neither the FROM table nor present in the joins list. Drizzle walks each selected field and checks the field's source table against the query's tables and join aliases; a miss means the SQL would reference an unjoined table, so it aborts.","triggerScenarios":"Selecting a column from table B in a query that only .from(tableA) without joining B; referencing an aliased table whose alias does not match what was registered in the join; selecting fields from a subquery alias that was not added. Common with nested selections or when copy-pasting a field into a different query.","commonSituations":"Refactoring a query and dropping a join while keeping the column reference; aliasing a table on join (alias: 't') but referencing the original table name in the select; building queries dynamically from a shared field map.","solutions":["Add the missing .leftJoin(...) / .innerJoin(...) for the table that owns the column.","When aliasing, reference the alias consistently in both the join and the selection.","If the column belongs to the base table, ensure you did not accidentally pass a different table's column object."],"exampleFix":"// before\ndb.select({ name: users.name, title: posts.title })\n  .from(users); // posts never joined -> throws\n\n// after\ndb.select({ name: users.name, title: posts.title })\n  .from(users)\n  .leftJoin(posts, eq(posts.authorId, users.id));","handlingStrategy":"validation","validationCode":"function assertTablesJoined(selectedTables: Set<string>, fromTable: string, joinAliases: string[]) {\n  const available = new Set([fromTable, ...joinAliases]);\n  for (const t of selectedTables) {\n    if (!available.has(t)) throw new Error(`Table ${t} referenced but not in FROM/joins`);\n  }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep selected fields and joins in the same builder function so they stay in sync.","When aliasing a table, use the alias object consistently in the selection.","After dropping a join, grep for columns of that table in the selection."],"tags":["select","joins","schema","query-builder"],"analyzedSha":"b7862528fd8fc39bc2653a6c18dad7c1f4e68d10","analyzedAt":"2026-08-03T18:11:14.318Z","schemaVersion":2}