{"record":{"id":"bac4b6abe91005f1","repo":"n8n-io/n8n","slug":"relation-this-relationpropertypath-was-not-foun","errorCode":null,"errorMessage":"Relation ${this.relationPropertyPath} was not found in entity ${this.mainAlias.name}","messagePattern":"Relation (.+?) was not found in entity (.+?)","errorType":"exception","errorClass":"TypeORMError","httpStatus":null,"severity":"error","filePath":"packages/@n8n/typeorm/src/query-builder/QueryExpressionMap.ts","lineNumber":460,"sourceCode":"\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\n\t\tconst relationMetadata = this.mainAlias.metadata.findRelationWithPropertyPath(\n\t\t\tthis.relationPropertyPath,\n\t\t);\n\t\tif (!relationMetadata)\n\t\t\tthrow new TypeORMError(\n\t\t\t\t`Relation ${this.relationPropertyPath} was not found in entity ${this.mainAlias.name}`,\n\t\t\t); // todo: better message\n\n\t\treturn relationMetadata;\n\t}\n\n\t/**\n\t * Copies all properties of the current QueryExpressionMap into a new one.\n\t * Useful when QueryBuilder needs to create a copy of itself.\n\t */\n\tclone(): QueryExpressionMap {\n\t\tconst map = new QueryExpressionMap(this.connection);\n\t\tmap.queryType = this.queryType;\n\t\tmap.selects = this.selects.map((select) => select);\n\t\tmap.maxExecutionTime = this.maxExecutionTime;\n\t\tmap.selectDistinct = this.selectDistinct;\n\t\tmap.selectDistinctOn = this.selectDistinctOn;\n\t\tthis.aliases.forEach((alias) => map.aliases.push(new Alias(alias)));","sourceCodeStart":442,"sourceCodeEnd":478,"githubUrl":"https://github.com/n8n-io/n8n/blob/5ac6606e81f67bb9534255570cd4e86fd8101eee/packages/@n8n/typeorm/src/query-builder/QueryExpressionMap.ts#L442-L478","documentation":"After mainAlias is confirmed present, the relationMetadata getter walks the entity metadata via findRelationWithPropertyPath(this.relationPropertyPath). If the relation path supplied to .relation() does not correspond to any @OneToMany/@ManyToOne/@ManyToMany/@OneToOne on the entity, it throws TypeORMError naming the bad path and the entity alias.","triggerScenarios":"qb.relation('User.gruops') typo; calling .relation() with a path that points at a plain @Column instead of a relation; referencing a relation that exists on the inverse entity but not on this side; deep path like 'a.b.c' where an intermediate segment is not a relation.","commonSituations":"Renaming a relation property in the entity without updating call sites; assuming a relation exists from both sides when only one side declares @ManyToOne; copy-paste between entities with different relation names.","solutions":["Open the entity class for mainAlias.metadata.targetName and confirm the exact @*ToOne decorator property name; correct the .relation() argument.","For nested paths, verify each segment is a relation (not a column) and that the relation is eager or already joined.","If you meant a column not a relation, use .set() on a normal update builder instead of the relation API."],"exampleFix":"// before\nawait qb.relation('User', 'gruops').of(user).add(g);\n// after\nawait qb.relation('User', 'groups').of(user).add(g);","handlingStrategy":"validation","validationCode":"import { DataSource } from 'typeorm';\n\nfunction assertRelation(ds: DataSource, target: Function, path: string) {\n  const meta = ds.getMetadata(target);\n  if (!meta.findRelationWithPropertyPath(path))\n    throw new Error(`'${path}' is not a relation on ${meta.targetName}`);\n}","typeGuard":"function isRelationPath(ds: DataSource, target: Function, path: string): boolean {\n  return !!ds.getMetadata(target).findRelationWithPropertyPath(path);\n}","tryCatchPattern":null,"preventionTips":["Centralize relation-property names as string constants defined next to the entity.","Add a startup self-check that every relation name used in the codebase exists in metadata.","Prefer the typed lambda form of relation() over a raw string when the API supports it."],"tags":["typeorm","query-builder","relation","metadata"],"backgroundTag":null,"analyzedSha":"5ac6606e81f67bb9534255570cd4e86fd8101eee","analyzedAt":"2026-08-12T05:26:35.080Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}