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

Method applyTPTJoins

packages/sql/src/query/QueryBuilder.ts:3579–3615  ·  view source on GitHub ↗

* For TPT (Table-Per-Type) inheritance: INNER JOINs parent tables. * When querying a child entity, we need to join all parent tables. * Field selection is handled separately in addTPTParentFields().

()

Source from the content-addressed store, hash-verified

3577 * Field selection is handled separately in addTPTParentFields().
3578 */
3579 private applyTPTJoins(): void {
3580 const meta = this.mainAlias.meta;
3581
3582 if (
3583 meta?.inheritanceType !== 'tpt' ||
3584 !meta.tptParent ||
3585 ![QueryType.SELECT, QueryType.COUNT].includes(this.type)
3586 ) {
3587 return;
3588 }
3589
3590 if (this.#state.tptJoinsApplied) {
3591 return;
3592 }
3593 this.#state.tptJoinsApplied = true;
3594
3595 let childMeta: EntityMetadata = meta;
3596 let childAlias = this.mainAlias.aliasName;
3597
3598 while (childMeta.tptParent) {
3599 const parentMeta = childMeta.tptParent;
3600 const parentAlias = this.getNextAlias(parentMeta.className);
3601 this.createAlias(parentMeta.class, parentAlias);
3602 this.#state.tptAlias[parentMeta.className] = parentAlias;
3603
3604 this.addPropertyJoin(
3605 childMeta.tptParentProp!,
3606 childAlias,
3607 parentAlias,
3608 JoinType.innerJoin,
3609 `[tpt]${childMeta.className}`,
3610 );
3611
3612 childMeta = parentMeta;
3613 childAlias = parentAlias;
3614 }
3615 }
3616
3617 /**
3618 * For TPT inheritance: adds field selections from parent tables.

Callers 2

ensureTPTJoinsMethod · 0.95
finalizeMethod · 0.95

Calls 3

getNextAliasMethod · 0.95
createAliasMethod · 0.95
addPropertyJoinMethod · 0.95

Tested by

no test coverage detected