* 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().
()
| 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. |
no test coverage detected