{"record":{"id":"fb3c3a96425c80f9","repo":"n8n-io/n8n","slug":"aliasname-alias-was-not-found-maybe-you-forg","errorCode":null,"errorMessage":"\"${aliasName}\" alias was not found. Maybe you forgot to join it?","messagePattern":"\"(.+?)\" alias was not found\\. Maybe you forgot to join it\\?","errorType":"exception","errorClass":"TypeORMError","httpStatus":null,"severity":"error","filePath":"packages/@n8n/typeorm/src/query-builder/QueryExpressionMap.ts","lineNumber":437,"sourceCode":"\t\tif (aliasName) alias.name = aliasName;\n\t\tif (options.metadata) alias.metadata = options.metadata;\n\t\tif (options.target && !alias.hasMetadata)\n\t\t\talias.metadata = this.connection.getMetadata(options.target);\n\t\tif (options.tablePath) alias.tablePath = options.tablePath;\n\t\tif (options.subQuery) alias.subQuery = options.subQuery;\n\n\t\tthis.aliases.push(alias);\n\t\treturn alias;\n\t}\n\n\t/**\n\t * Finds alias with the given name.\n\t * If alias was not found it throw an exception.\n\t */\n\tfindAliasByName(aliasName: string): Alias {\n\t\tconst alias = this.aliases.find((alias) => alias.name === aliasName);\n\t\tif (!alias)\n\t\t\tthrow new TypeORMError(`\"${aliasName}\" alias was not found. Maybe you forgot to join it?`);\n\n\t\treturn alias;\n\t}\n\n\tfindColumnByAliasExpression(aliasExpression: string): ColumnMetadata | undefined {\n\t\tconst [aliasName, propertyPath] = aliasExpression.split('.');\n\t\tconst alias = this.findAliasByName(aliasName);\n\t\treturn alias.metadata.findColumnWithPropertyName(propertyPath);\n\t}\n\n\t/**\n\t * Gets relation metadata of the relation this query builder works with.\n\t *\n\t * todo: add proper exceptions\n\t */\n\tget relationMetadata(): RelationMetadata {\n\t\tif (!this.mainAlias) throw new TypeORMError(`Entity to work with is not specified!`); // todo: better message\n","sourceCodeStart":419,"sourceCodeEnd":455,"githubUrl":"https://github.com/n8n-io/n8n/blob/5ac6606e81f67bb9534255570cd4e86fd8101eee/packages/@n8n/typeorm/src/query-builder/QueryExpressionMap.ts#L419-L455","documentation":"QueryExpressionMap.findAliasByName iterates this.aliases and throws TypeORMError when no alias with the given name was ever registered. Aliases are created by from/leftJoin/innerJoin etc.; referencing an alias name that does not match any of them is a programmer error.","triggerScenarios":"Using qb.andWhere('otherAlias.col = :v') before calling qb.lefteftJoin('Entity','otherAlias'); typoing the alias name in a raw where string; referencing an alias after it was scoped out by a subquery; using getSql() of an inner builder whose alias name you reused verbatim outside its scope.","commonSituations":"Refactor that renames a join alias but leaves string-fragment conditions using the old name; copy-pasting a where fragment between builders whose join aliases differ; passing unqualified column names that TypeORM splits on '.' assuming alias.column.","solutions":["Audit every string condition in the failing builder for '<alias>.' prefixes and ensure each alias was created with a from()/join() call earlier in the chain.","Prefer the lambda form qb.andWhere(alias + '.col = :v') where alias is a variable, not a literal, so renames propagate.","Add the missing qb.leftJoin(Entity, aliasName) before the condition that uses it."],"exampleFix":"// before\nqb.andWhere('orders.total > :t', { t: 100 }); // 'orders' never joined\n// after\nqb.leftJoin('user.orders','orders').andWhere('orders.total > :t', { t: 100 });","handlingStrategy":"validation","validationCode":"function assertAliasExists(qb: any, alias: string) {\n  const map = qb.expressionMap;\n  if (!map.aliases.some((a: any) => a.name === alias))\n    throw new Error(`Alias '${alias}' not joined. Call .leftJoin/.innerJoin first.`);\n}","typeGuard":"function isKnownAlias(qb: any, alias: string): boolean {\n  return qb.expressionMap.aliases.some((a: any) => a.name === alias);\n}","tryCatchPattern":null,"preventionTips":["Keep join alias names in variables and interpolate them into string conditions.","Add a unit test asserting every alias referenced in a where fragment is created in the same builder.","Avoid string-concatenated SQL fragments that hardcode alias names."],"tags":["typeorm","query-builder","alias","joins"],"backgroundTag":null,"analyzedSha":"5ac6606e81f67bb9534255570cd4e86fd8101eee","analyzedAt":"2026-08-12T05:26:35.080Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}