@mikro-orm/core 6.6.15-dev.0 → 6.6.15-dev.2

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
@@ -735,7 +735,7 @@ class EntityManager {
735
735
  }
736
736
  }
737
737
  const data2 = await this.driver.findOne(meta.className, where, {
738
- fields: returning,
738
+ fields: returning.concat(...(options.onConflictMergeFields ?? [])),
739
739
  ctx: em.transactionContext,
740
740
  convertCustomTypes: true,
741
741
  connectionType: 'write',
@@ -883,10 +883,11 @@ class EntityManager {
883
883
  entities.set(entity, row);
884
884
  entitiesByData.set(row, entity);
885
885
  });
886
- // skip if we got the PKs via returning statement (`rows`)
886
+ // skip the reload only when RETURNING brought back a row for every input
887
+ // (onConflictWhere can suppress writes, leaving some rows out)
887
888
  const uniqueFields = options.onConflictFields ?? (utils_1.Utils.isPlainObject(allWhere[0]) ? Object.keys(allWhere[0]).flatMap(key => utils_1.Utils.splitPrimaryKeys(key)) : meta.primaryKeys);
888
889
  const returning = (0, utils_1.getOnConflictReturningFields)(meta, data[0], uniqueFields, options);
889
- const reloadFields = returning.length > 0 && !(this.getPlatform().usesReturningStatement() && res.rows?.length);
890
+ const reloadFields = returning.length > 0 && !(this.getPlatform().usesReturningStatement() && res.rows?.length === data.length);
890
891
  if (options.onConflictAction === 'ignore' || (!res.rows?.length && loadPK.size > 0) || reloadFields) {
891
892
  const unique = meta.hydrateProps.filter(p => !p.lazy).map(p => p.name);
892
893
  const add = new Set(propIndex !== false && propIndex >= 0 ? [unique[propIndex]] : []);
@@ -903,7 +904,7 @@ class EntityManager {
903
904
  });
904
905
  }
905
906
  const data2 = await this.driver.find(meta.className, where, {
906
- fields: returning.concat(...add).concat(...(Array.isArray(uniqueFields) ? uniqueFields : [])),
907
+ fields: returning.concat(...add).concat(...(Array.isArray(uniqueFields) ? uniqueFields : [])).concat(...(options.onConflictMergeFields ?? [])),
907
908
  ctx: em.transactionContext,
908
909
  convertCustomTypes: true,
909
910
  connectionType: 'write',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/core",
3
- "version": "6.6.15-dev.0",
3
+ "version": "6.6.15-dev.2",
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
  "main": "index.js",
6
6
  "module": "index.mjs",
@@ -64,7 +64,7 @@
64
64
  "esprima": "4.0.1",
65
65
  "fs-extra": "11.3.3",
66
66
  "globby": "11.1.0",
67
- "mikro-orm": "6.6.15-dev.0",
67
+ "mikro-orm": "6.6.15-dev.2",
68
68
  "reflect-metadata": "0.2.2"
69
69
  }
70
70
  }
@@ -47,7 +47,8 @@ class QueryHelper {
47
47
  }
48
48
  const keys = Object.keys(where);
49
49
  const groupOperator = keys.find(k => {
50
- return Utils_1.Utils.isGroupOperator(k) && Array.isArray(where[k]) && where[k].every(cond => {
50
+ // sole-key only: caller drops the parent, so siblings would be silently lost
51
+ return keys.length === 1 && Utils_1.Utils.isGroupOperator(k) && Array.isArray(where[k]) && where[k].every(cond => {
51
52
  return Utils_1.Utils.isPlainObject(cond) && Object.keys(cond).every(k2 => {
52
53
  if (Utils_1.Utils.isOperator(k2, false)) {
53
54
  if (k2 === '$not') {