@mikro-orm/core 7.2.13-dev.2 → 7.2.13-dev.3

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.
@@ -96,12 +96,13 @@ export class Collection {
96
96
  return (this.#count = this.length);
97
97
  }
98
98
  let count;
99
+ let cond = this.property.where ? { $and: [where ?? {}, this.property.where] } : where;
99
100
  if (dataloader ?? [DataloaderType.ALL, DataloaderType.COLLECTION].includes(em.config.getDataloaderType())) {
100
101
  const loader = await em.getDataLoader('count');
101
- count = await loader.load([this, { where, ...countOptions }]);
102
+ count = await loader.load([this, { where: cond, ...countOptions }]);
102
103
  }
103
104
  else {
104
- const cond = this.createLoadCountCondition(where ?? {});
105
+ cond = this.createLoadCountCondition(cond ?? {});
105
106
  count = await em.count(this.property.targetMeta.class, cond, countOptions);
106
107
  }
107
108
  if (!where) {
@@ -133,7 +134,7 @@ export class Collection {
133
134
  items = (await em.find(this.property.targetMeta.class, this.createCondition(where), opts));
134
135
  }
135
136
  if (options.store) {
136
- this.hydrate(items, true);
137
+ this.hydrate(items, true, undefined, undefined, false);
137
138
  this.setSerializationContext(options);
138
139
  this.populated();
139
140
  this.#readonly = true;
@@ -494,7 +495,7 @@ export class Collection {
494
495
  this.#initialized = true;
495
496
  this.#partial = !!partial;
496
497
  this.#items.clear();
497
- this.#count = count ? 0 : undefined;
498
+ this.#count = count && !partial ? 0 : undefined;
498
499
  // loaded items are not persisted, that would queue an auto-flush of their type on a read-only path
499
500
  const unwrapped = items.map(i => Reference.unwrapReference(i));
500
501
  this.addItems(unwrapped, hydration);
@@ -734,7 +734,7 @@ export class EntityLoader {
734
734
  return this.#em.getUnitOfWork().register(entity, undefined, { loaded: true });
735
735
  });
736
736
  const hasLimit = populate?.limit != null;
737
- entity[prop.name].hydrate(items, true, hasLimit, hasLimit);
737
+ entity[prop.name].hydrate(items, true, hasLimit, hasLimit, Utils.isEmpty(where));
738
738
  children.push(items);
739
739
  }
740
740
  return children;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/core",
3
- "version": "7.2.13-dev.2",
3
+ "version": "7.2.13-dev.3",
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",
@@ -443,7 +443,7 @@ export class Platform {
443
443
  }
444
444
  getJsonValueType(value) {
445
445
  if (Array.isArray(value)) {
446
- return typeof value[0];
446
+ return typeof value.find(v => v !== null);
447
447
  }
448
448
  if (Utils.isPlainObject(value) && Object.keys(value).every(k => Utils.isOperator(k))) {
449
449
  return this.getJsonValueType(Object.values(value)[0]);
@@ -281,7 +281,8 @@ export class DataloaderUtils {
281
281
  const { where, ...countOpts } = group.opts;
282
282
  const conditions = [{ [group.fkProp]: { $in: allPKs } }];
283
283
  if (where) {
284
- conditions.push(where);
284
+ // for M:N the query targets the pivot entity, so the condition goes through its target relation
285
+ conditions.push(group.targetFilterProp ? { [group.targetFilterProp]: where } : where);
285
286
  }
286
287
  // For M:N, apply the target entity's filters through the pivot's target relation
287
288
  if (group.targetFilterProp) {
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.13-dev.2';
156
+ static #ORM_VERSION = '7.2.13-dev.3';
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}`;