typeorm/typeorm · error · TypeORMError

Relation with property path ${this.relationPropertyPath} in

Error message

Relation with property path ${this.relationPropertyPath} in entity was not found.

What it means

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.

Source

Thrown at src/query-builder/relation-id/RelationIdAttribute.ts:113

     * Relation of the parent.
     * This is used to understand what is joined.
     * This is available when join was made using "post.category" syntax.
     */
    get relation(): RelationMetadata {
        if (!QueryBuilderUtils.isAliasProperty(this.relationName))
            throw new TypeORMError(
                `Given value must be a string representation of alias property`,
            )

        const relationOwnerSelection = this.queryExpressionMap.findAliasByName(
            this.parentAlias!,
        )
        const relation =
            relationOwnerSelection.metadata.findRelationWithPropertyPath(
                this.relationPropertyPath!,
            )
        if (!relation)
            throw new TypeORMError(
                `Relation with property path ${this.relationPropertyPath} in entity was not found.`,
            )
        return relation
    }

    /**
     * Generates alias of junction table, whose ids we get.
     */
    get junctionAlias(): string {
        const [parentAlias, relationProperty] = this.relationName.split(".")
        return parentAlias + "_" + relationProperty + "_rid"
    }

    /**
     * Metadata of the joined entity.
     * If extra condition without entity was joined, then it will return undefined.
     */
    get junctionMetadata(): EntityMetadata {

View on GitHub (pinned to 04ff4daedc)

Solutions

  1. Open the entity class behind the alias and confirm the relation exists as a decorated property with the exact spelling/path used in loadRelationIdAndMap.
  2. Use the TypeScript property path, not the database column name, and navigate embedded paths correctly.
  3. Verify the alias prefix resolves to the entity that actually owns the relation.

Example fix

// before — Post has no `categories` relation
qb.loadRelationIdAndMap("post.categoryIds", "post.categories")
// after — use the real relation name, or add the @ManyToMany relation
qb.loadRelationIdAndMap("post.categoryIds", "post.tags")
Defensive patterns

Strategy: validation

Validate before calling

function relationExists(
  dataSource: import("typeorm").DataSource,
  entityTarget: any,
  aliasDotProp: string,
): boolean {
  const [, prop] = aliasDotProp.split(".")
  const meta = dataSource.getMetadata(entityTarget)
  return !!meta.findRelationWithPropertyPath(prop)
}

if (!relationExists(dataSource, Post, rel)) {
  throw new Error(`No relation '${rel}' on Post`)
}

Type guard

function isKnownRelation(
  meta: import("typeorm").EntityMetadata,
  propertyPath: string,
): boolean {
  return !!meta.findRelationWithPropertyPath(propertyPath)
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of typeorm/typeorm@04ff4daedc (2026-08-03). Data as JSON: /data/errors/18a3c76e00b0e2c7.json. Report an issue: GitHub.