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

Method addTPTParentFields

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

* For TPT inheritance: adds field selections from parent tables.

()

Source from the content-addressed store, hash-verified

3618 * For TPT inheritance: adds field selections from parent tables.
3619 */
3620 private addTPTParentFields(): void {
3621 const meta = this.mainAlias.meta;
3622
3623 if (
3624 meta?.inheritanceType !== 'tpt' ||
3625 !meta.tptParent ||
3626 ![QueryType.SELECT, QueryType.COUNT].includes(this.type)
3627 ) {
3628 return;
3629 }
3630
3631 if (!this.#state.fields?.includes('*') && !this.#state.fields?.includes(`${this.mainAlias.aliasName}.*`)) {
3632 return;
3633 }
3634
3635 let parentMeta: EntityMetadata<Entity> | undefined = meta.tptParent;
3636 while (parentMeta) {
3637 const parentAlias = this.#state.tptAlias[parentMeta.className];
3638 if (parentAlias) {
3639 const schema = parentMeta.schema === '*' ? '*' : this.driver.getSchemaName(parentMeta);
3640 parentMeta
3641 .ownProps!.filter(prop => this.platform.shouldHaveColumn(prop, []))
3642 .forEach(prop =>
3643 this.#state.fields!.push(...this.driver.mapPropToFieldNames(this, prop, parentAlias, parentMeta!, schema)),
3644 );
3645 }
3646 parentMeta = parentMeta.tptParent;
3647 }
3648 }
3649
3650 /**
3651 * For TPT polymorphic queries: LEFT JOINs all child tables when querying a TPT base class.

Callers 1

finalizeMethod · 0.95

Calls 4

filterMethod · 0.80
pushMethod · 0.80
getSchemaNameMethod · 0.65
shouldHaveColumnMethod · 0.45

Tested by

no test coverage detected