{"id":"18a3c76e00b0e2c7","repo":"typeorm/typeorm","slug":"relation-with-property-path-this-relationpropert-18a3c7","errorCode":null,"errorMessage":"Relation with property path ${this.relationPropertyPath} in entity was not found.","messagePattern":"Relation with property path (.+?) in entity was not found\\.","errorType":"exception","errorClass":"TypeORMError","httpStatus":null,"severity":"error","filePath":"src/query-builder/relation-id/RelationIdAttribute.ts","lineNumber":113,"sourceCode":"     * Relation of the parent.\n     * This is used to understand what is joined.\n     * This is available when join was made using \"post.category\" syntax.\n     */\n    get relation(): RelationMetadata {\n        if (!QueryBuilderUtils.isAliasProperty(this.relationName))\n            throw new TypeORMError(\n                `Given value must be a string representation of alias property`,\n            )\n\n        const relationOwnerSelection = this.queryExpressionMap.findAliasByName(\n            this.parentAlias!,\n        )\n        const relation =\n            relationOwnerSelection.metadata.findRelationWithPropertyPath(\n                this.relationPropertyPath!,\n            )\n        if (!relation)\n            throw new TypeORMError(\n                `Relation with property path ${this.relationPropertyPath} in entity was not found.`,\n            )\n        return relation\n    }\n\n    /**\n     * Generates alias of junction table, whose ids we get.\n     */\n    get junctionAlias(): string {\n        const [parentAlias, relationProperty] = this.relationName.split(\".\")\n        return parentAlias + \"_\" + relationProperty + \"_rid\"\n    }\n\n    /**\n     * Metadata of the joined entity.\n     * If extra condition without entity was joined, then it will return undefined.\n     */\n    get junctionMetadata(): EntityMetadata {","sourceCodeStart":95,"sourceCodeEnd":131,"githubUrl":"https://github.com/typeorm/typeorm/blob/04ff4daedcf60fa4ffd0d5d33bbafaac1a9bbc96/src/query-builder/relation-id/RelationIdAttribute.ts#L95-L131","documentation":"Thrown by RelationIdAttribute.relation when the 'alias.property' string is well-formed and the alias resolves to a selection, but no relation metadata is found at that property path on the parent entity. findRelationWithPropertyPath returns undefined, meaning the property is not a @ManyToOne/@OneToMany/@OneToOne/@ManyToMany on the entity behind the alias.","triggerScenarios":"Calling loadRelationIdAndMap('post.categoryIds', 'post.categories') when Post has no 'categories' relation; a typo in the property path; referencing an embedded or plain column instead of a relation; the relation is defined on a different entity than the one the alias points to.","commonSituations":"Renaming a relation property in the entity but not in the query; forgetting to add the @ManyToMany/@ManyToOne decorator; using the database column name instead of the TypeScript property name; pointing the alias at the wrong table.","solutions":["Open the entity class behind the alias and confirm the relation exists as a decorated property with the exact spelling/path used in loadRelationIdAndMap.","Use the TypeScript property path, not the database column name, and navigate embedded paths correctly.","Verify the alias prefix resolves to the entity that actually owns the relation."],"exampleFix":"// before — Post has no `categories` relation\nqb.loadRelationIdAndMap(\"post.categoryIds\", \"post.categories\")\n// after — use the real relation name, or add the @ManyToMany relation\nqb.loadRelationIdAndMap(\"post.categoryIds\", \"post.tags\")","handlingStrategy":"validation","validationCode":"function relationExists(\n  dataSource: import(\"typeorm\").DataSource,\n  entityTarget: any,\n  aliasDotProp: string,\n): boolean {\n  const [, prop] = aliasDotProp.split(\".\")\n  const meta = dataSource.getMetadata(entityTarget)\n  return !!meta.findRelationWithPropertyPath(prop)\n}\n\nif (!relationExists(dataSource, Post, rel)) {\n  throw new Error(`No relation '${rel}' on Post`)\n}","typeGuard":"function isKnownRelation(\n  meta: import(\"typeorm\").EntityMetadata,\n  propertyPath: string,\n): boolean {\n  return !!meta.findRelationWithPropertyPath(propertyPath)\n}","tryCatchPattern":null,"preventionTips":["Use the exact TypeScript relation property name, not the DB column name.","After renaming a relation, grep for its old name in query-builder calls.","Confirm the alias points to the entity that owns the relation."],"tags":["query-builder","relation-id","metadata","typo"],"analyzedSha":"04ff4daedcf60fa4ffd0d5d33bbafaac1a9bbc96","analyzedAt":"2026-08-03T18:27:32.281Z","schemaVersion":2}