@mikro-orm/core 7.2.8-dev.12 → 7.2.8-dev.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -73,6 +73,7 @@ export declare class EntityLoader {
73
73
  private initializeCollections;
74
74
  private initializeOneToMany;
75
75
  private initializeManyToMany;
76
+ private initializePartitions;
76
77
  private findChildren;
77
78
  private mergePrimaryCondition;
78
79
  private populateField;
@@ -186,7 +186,7 @@ export class EntityLoader {
186
186
  if (prop.polymorphic && prop.polymorphTargets) {
187
187
  return this.populatePolymorphic(entities, prop, options, !!ref);
188
188
  }
189
- const { items, partial } = await this.findChildren(options.filtered ?? entities, prop, populate, {
189
+ const { items, partial, partitions } = await this.findChildren(options.filtered ?? entities, prop, populate, {
190
190
  ...options,
191
191
  where,
192
192
  orderBy: mergedOrderBy,
@@ -194,6 +194,10 @@ export class EntityLoader {
194
194
  const hasLimit = populate.limit != null;
195
195
  const isPartial = partial || hasLimit;
196
196
  const customOrder = mergedOrderBy.length > 0 || !!prop.orderBy || !!prop.targetMeta?.orderBy;
197
+ if (partitions) {
198
+ this.initializePartitions(filtered, items, field, partitions);
199
+ return items;
200
+ }
197
201
  this.initializeCollections(filtered, prop, field, items, customOrder, isPartial, hasLimit);
198
202
  return items;
199
203
  }
@@ -336,6 +340,18 @@ export class EntityLoader {
336
340
  }
337
341
  }
338
342
  }
343
+ initializePartitions(filtered, children, field, partitions) {
344
+ // a child belongs only to the owners whose slice returned it, not to every owner in its array
345
+ const key = (entity) => helper(entity).getSerializedPrimaryKey();
346
+ const owners = new Map(filtered.map(entity => [key(entity), []]));
347
+ const items = new Map(children.map(child => [key(child), child]));
348
+ for (const [owner, child] of partitions) {
349
+ owners.get('' + owner)?.push(items.get('' + child));
350
+ }
351
+ for (const entity of filtered) {
352
+ entity[field].hydrate(owners.get(key(entity)), true, true, true);
353
+ }
354
+ }
339
355
  async findChildren(entities, prop, populate, options, ref) {
340
356
  const children = Utils.unique(this.getChildReferences(entities, prop, options, ref, populate));
341
357
  const meta = prop.targetMeta;
@@ -434,11 +450,13 @@ export class EntityLoader {
434
450
  visited: options.visited,
435
451
  };
436
452
  if (populate.limit != null) {
437
- findOptions._partitionLimit = {
438
- partitionBy: fk,
439
- limit: populate.limit,
440
- offset: populate.offset,
441
- };
453
+ // the owners of an M:N without a pivot table are stored as an array, the driver slices per owner
454
+ const owners = prop.kind === ReferenceKind.MANY_TO_MANY && ownerProp ? ids : undefined;
455
+ findOptions._partitionLimit = { partitionBy: fk, limit: populate.limit, offset: populate.offset, owners };
456
+ // a cached result would not carry the per-owner partitions the driver writes back
457
+ if (owners) {
458
+ findOptions.cache = false;
459
+ }
442
460
  }
443
461
  const items = await this.#em.find(meta.class, where, findOptions);
444
462
  // For targetKey relations, wire up loaded entities to parent references
@@ -501,7 +519,7 @@ export class EntityLoader {
501
519
  this.#em.getUnitOfWork().unmarkAsLoaded(item);
502
520
  }
503
521
  }
504
- return { items, partial };
522
+ return { items, partial, partitions: findOptions._partitionLimit?.partitions };
505
523
  }
506
524
  mergePrimaryCondition(ids, pk, options, meta, metadata, platform) {
507
525
  const cond1 = QueryHelper.processWhere({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/core",
3
- "version": "7.2.8-dev.12",
3
+ "version": "7.2.8-dev.13",
4
4
  "description": "TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, PostgreSQL and SQLite databases as well as usage with vanilla JavaScript.",
5
5
  "keywords": [
6
6
  "data-mapper",
package/utils/Utils.js CHANGED
@@ -153,7 +153,7 @@ export function parseJsonSafe(value) {
153
153
  /** Collection of general-purpose utility methods used throughout the ORM. */
154
154
  export class Utils {
155
155
  static PK_SEPARATOR = '~~~';
156
- static #ORM_VERSION = '7.2.8-dev.12';
156
+ static #ORM_VERSION = '7.2.8-dev.13';
157
157
  /** Default session variable name backing an RLS filter argument (`current_setting('mikro.<filter>.<arg>')`). */
158
158
  static getRlsSettingName(filterName, argName) {
159
159
  return `mikro.${filterName}.${argName}`;