@mikro-orm/core 7.1.9-dev.10 → 7.1.9-dev.11

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/core",
3
- "version": "7.1.9-dev.10",
3
+ "version": "7.1.9-dev.11",
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",
@@ -237,7 +237,8 @@ export class ChangeSetPersister {
237
237
  for (const changeSet of changeSets) {
238
238
  if (res.rows) {
239
239
  const row = map.get(helper(changeSet.entity).getSerializedPrimaryKey());
240
- this.mapReturnedValues(changeSet.entity, changeSet.payload, row, meta);
240
+ // STI batches can mix child types, so map through the change set's own metadata
241
+ this.mapReturnedValues(changeSet.entity, changeSet.payload, row, changeSet.meta);
241
242
  }
242
243
  changeSet.persisted = true;
243
244
  }
@@ -378,7 +379,8 @@ export class ChangeSetPersister {
378
379
  changeSets.forEach(cs => {
379
380
  Utils.keys(cs.payload).forEach(k => {
380
381
  if (isRaw(cs.payload[k]) && isRaw(cs.entity[k])) {
381
- returning.add(meta.properties[k]);
382
+ // STI batches can mix child types, so the property might not exist on `meta`
383
+ returning.add(cs.meta.properties[k]);
382
384
  }
383
385
  });
384
386
  });
@@ -403,12 +405,14 @@ export class ChangeSetPersister {
403
405
  options = this.prepareOptions(meta, options, {
404
406
  fields: Utils.unique(reloadProps.map(prop => prop.name)),
405
407
  });
406
- const data = await this.#driver.find(meta.class, { [pk]: { $in: pks } }, options);
408
+ // a mixed STI batch shares one table but the child discriminator would filter out the siblings
409
+ const target = changeSets.some(cs => cs.meta !== meta) && meta.root.discriminatorColumn ? meta.root : meta;
410
+ const data = await this.#driver.find(target.class, { [pk]: { $in: pks } }, options);
407
411
  const map = new Map();
408
412
  data.forEach(item => map.set(Utils.getCompositeKeyHash(item, meta, false, this.#platform, true), item));
409
413
  for (const changeSet of changeSets) {
410
414
  const data = map.get(helper(changeSet.entity).getSerializedPrimaryKey());
411
- this.#hydrator.hydrate(changeSet.entity, meta, data, this.#factory, 'full', false, true);
415
+ this.#hydrator.hydrate(changeSet.entity, changeSet.meta, data, this.#factory, 'full', false, true);
412
416
  Object.assign(changeSet.payload, data); // merge to the changeset payload, so it gets saved to the entity snapshot
413
417
  }
414
418
  }
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.1.9-dev.10';
156
+ static #ORM_VERSION = '7.1.9-dev.11';
157
157
  /**
158
158
  * Checks if the argument is instance of `Object`. Returns false for arrays.
159
159
  */