@mikro-orm/core 7.1.1-dev.10 → 7.1.1-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/EntityManager.js CHANGED
@@ -863,7 +863,7 @@ export class EntityManager {
863
863
  }
864
864
  }
865
865
  const data2 = await this.driver.findOne(meta.class, where, {
866
- fields: returning,
866
+ fields: returning.concat(...(options.onConflictMergeFields ?? [])),
867
867
  ctx: em.#transactionContext,
868
868
  convertCustomTypes: true,
869
869
  connectionType: 'write',
@@ -1031,11 +1031,12 @@ export class EntityManager {
1031
1031
  entities.set(entity, row);
1032
1032
  entitiesByData.set(row, entity);
1033
1033
  });
1034
- // skip if we got the PKs via returning statement (`rows`)
1034
+ // skip the reload only when RETURNING brought back a row for every input
1035
+ // (onConflictWhere can suppress writes, leaving some rows out)
1035
1036
  // oxfmt-ignore
1036
1037
  const uniqueFields = options.onConflictFields ?? (Utils.isPlainObject(allWhere[0]) ? Object.keys(allWhere[0]).flatMap(key => Utils.splitPrimaryKeys(key)) : meta.primaryKeys);
1037
1038
  const returning = getOnConflictReturningFields(meta, data[0], uniqueFields, options);
1038
- const reloadFields = returning.length > 0 && !(this.getPlatform().usesReturningStatement() && res.rows?.length);
1039
+ const reloadFields = returning.length > 0 && !(this.getPlatform().usesReturningStatement() && res.rows?.length === data.length);
1039
1040
  if (options.onConflictAction === 'ignore' || (!res.rows?.length && loadPK.size > 0) || reloadFields) {
1040
1041
  const unique = meta.hydrateProps.filter(p => !p.lazy).map(p => p.name);
1041
1042
  const add = new Set(propIndex !== false && propIndex >= 0
@@ -1055,7 +1056,8 @@ export class EntityManager {
1055
1056
  const data2 = await this.driver.find(meta.class, where, {
1056
1057
  fields: returning
1057
1058
  .concat(...add)
1058
- .concat(...(Array.isArray(uniqueFields) ? uniqueFields : [])),
1059
+ .concat(...(Array.isArray(uniqueFields) ? uniqueFields : []))
1060
+ .concat(...(options.onConflictMergeFields ?? [])),
1059
1061
  ctx: em.#transactionContext,
1060
1062
  convertCustomTypes: true,
1061
1063
  connectionType: 'write',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/core",
3
- "version": "7.1.1-dev.10",
3
+ "version": "7.1.1-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",
package/utils/Utils.js CHANGED
@@ -141,7 +141,7 @@ export function parseJsonSafe(value) {
141
141
  /** Collection of general-purpose utility methods used throughout the ORM. */
142
142
  export class Utils {
143
143
  static PK_SEPARATOR = '~~~';
144
- static #ORM_VERSION = '7.1.1-dev.10';
144
+ static #ORM_VERSION = '7.1.1-dev.11';
145
145
  /**
146
146
  * Checks if the argument is instance of `Object`. Returns false for arrays.
147
147
  */