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

Method mapFlatCompositePrimaryKey

packages/core/src/utils/Utils.ts:606–628  ·  view source on GitHub ↗

* Maps nested FKs from `[1, 2, 3]` to `[1, [2, 3]]`.

(
    fk: Primary<any>[],
    prop: EntityProperty,
    fieldNames = prop.fieldNames,
    idx = 0,
  )

Source from the content-addressed store, hash-verified

604 * Maps nested FKs from `[1, 2, 3]` to `[1, [2, 3]]`.
605 */
606 static mapFlatCompositePrimaryKey(
607 fk: Primary<any>[],
608 prop: EntityProperty,
609 fieldNames = prop.fieldNames,
610 idx = 0,
611 ): Primary<any> | Primary<any>[] {
612 if (!prop.targetMeta) {
613 return fk[idx++];
614 }
615
616 const parts: Primary<any>[] = [];
617
618 for (const pk of prop.targetMeta.getPrimaryProps()) {
619 parts.push(this.mapFlatCompositePrimaryKey(fk, pk, fieldNames, idx));
620 idx += pk.fieldNames.length;
621 }
622
623 if (parts.length < 2) {
624 return parts[0];
625 }
626
627 return parts;
628 }
629
630 static getPrimaryKeyCondFromArray<T extends object>(
631 pks: Primary<T>[],

Callers 1

mapJoinedPropFunction · 0.80

Calls 2

getPrimaryPropsMethod · 0.80
pushMethod · 0.80

Tested by

no test coverage detected