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

Function buildPivotResultMap

packages/sql/src/AbstractSqlDriver.ts:2204–2227  ·  view source on GitHub ↗

* Build a map from owner PKs to their related entities from pivot table results.

(
    owners: Primary<O>[][],
    results: object[],
    keyProp: string,
    valueProp: string,
  )

Source from the content-addressed store, hash-verified

2202 * Build a map from owner PKs to their related entities from pivot table results.
2203 */
2204 private buildPivotResultMap<T extends object, O extends object>(
2205 owners: Primary<O>[][],
2206 results: object[],
2207 keyProp: string,
2208 valueProp: string,
2209 ): Dictionary<T[]> {
2210 const map: Dictionary<T[]> = {};
2211
2212 for (const owner of owners) {
2213 const key = Utils.getPrimaryKeyHash(owner as string[]);
2214 map[key] = [];
2215 }
2216
2217 for (const item of results) {
2218 const key = Utils.getPrimaryKeyHash(Utils.asArray((item as any)[keyProp]));
2219 const entity = (item as any)[valueProp] as T;
2220
2221 if (map[key]) {
2222 map[key].push(entity);
2223 }
2224 }
2225
2226 return map;
2227 }
2228
2229 private wrapPopulateFilter(options: FindOptions<any, any, any, any> | undefined, propName: string): any {
2230 if (!Utils.isEmpty(options?.populateFilter) || RawQueryFragment.hasObjectFragments(options?.populateFilter)) {

Callers

nothing calls this directly

Calls 3

getPrimaryKeyHashMethod · 0.80
asArrayMethod · 0.80
pushMethod · 0.80

Tested by

no test coverage detected