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

Method addPolymorphicJoin

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

* Registers a join for a specific polymorphic target type. * Used by the driver to create per-target LEFT JOINs for JOINED loading. * @internal

(
    prop: EntityProperty,
    targetMeta: EntityMetadata,
    ownerAlias: string,
    alias: string,
    type: JoinType,
    path: string,
    schema?: string,
  )

Source from the content-addressed store, hash-verified

2411 * @internal
2412 */
2413 addPolymorphicJoin(
2414 prop: EntityProperty,
2415 targetMeta: EntityMetadata,
2416 ownerAlias: string,
2417 alias: string,
2418 type: JoinType,
2419 path: string,
2420 schema?: string,
2421 ): void {
2422 // Override referencedColumnNames to use the specific target's PK columns
2423 // (polymorphic targets may have different PK column names, e.g. org_id vs user_id)
2424 const referencedColumnNames = targetMeta.getPrimaryProps().flatMap(pk => pk.fieldNames);
2425 const targetProp = { ...prop, targetMeta, referencedColumnNames } as EntityProperty;
2426 const aliasedName = `${ownerAlias}.${prop.name}[${targetMeta.className}]#${alias}`;
2427 this.#state.joins[aliasedName] = this.helper.joinManyToOneReference(
2428 targetProp,
2429 ownerAlias,
2430 alias,
2431 type,
2432 {},
2433 schema,
2434 );
2435 this.#state.joins[aliasedName].path = path;
2436 this.createAlias(targetMeta.class, alias);
2437 }
2438
2439 /**
2440 * @internal

Callers 1

getFieldsForJoinedLoadFunction · 0.80

Calls 3

createAliasMethod · 0.95
getPrimaryPropsMethod · 0.80

Tested by

no test coverage detected