MCPcopy Create free account
hub / github.com/mikro-orm/mikro-orm / addTPTParentJoinsForRelation

Function addTPTParentJoinsForRelation

packages/sql/src/AbstractSqlDriver.ts:2707–2731  ·  view source on GitHub ↗

* Walks the TPT inheritance chain of `leafMeta` and INNER JOINs each parent table. * Registers the parent aliases in `qb.state.tptAlias` so column resolution finds them * when filter conditions reference parent-table columns. * @internal

(
    qb: AnyQueryBuilder<T>,
    leafMeta: EntityMetadata,
    leafAlias: string,
    basePath: string,
  )

Source from the content-addressed store, hash-verified

2705 * @internal
2706 */
2707 protected addTPTParentJoinsForRelation<T extends object>(
2708 qb: AnyQueryBuilder<T>,
2709 leafMeta: EntityMetadata,
2710 leafAlias: string,
2711 basePath: string,
2712 ): void {
2713 let childAlias = leafAlias;
2714 let childMeta: EntityMetadata = leafMeta;
2715
2716 while (childMeta.tptParent) {
2717 const parentMeta = childMeta.tptParent;
2718 const parentAlias = qb.getNextAlias(parentMeta.className);
2719 qb.createAlias(parentMeta.class, parentAlias);
2720 qb.state.tptAlias[`${leafAlias}:${parentMeta.className}`] = parentAlias;
2721 qb.addPropertyJoin(
2722 childMeta.tptParentProp!,
2723 childAlias,
2724 parentAlias,
2725 JoinType.innerJoin,
2726 `${basePath}.[tpt]${childMeta.className}`,
2727 );
2728 childAlias = parentAlias;
2729 childMeta = parentMeta;
2730 }
2731 }
2732
2733 /**
2734 * Adds LEFT JOINs and fields for TPT polymorphic loading when populating a relation to a TPT base class.

Callers

nothing calls this directly

Calls 3

createAliasMethod · 0.80
addPropertyJoinMethod · 0.80
getNextAliasMethod · 0.65

Tested by

no test coverage detected