@mikro-orm/core 7.2.4-dev.12 → 7.2.4-dev.14

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
@@ -1248,7 +1248,10 @@ export class EntityManager {
1248
1248
  // skip the reload only when RETURNING brought back a row for every input
1249
1249
  // (onConflictWhere can suppress writes, leaving some rows out)
1250
1250
  // oxfmt-ignore
1251
- const uniqueFields = options.onConflictFields ?? (Utils.isPlainObject(allWhere[0]) ? Object.keys(allWhere[0]).flatMap(key => Utils.splitPrimaryKeys(key)) : meta.primaryKeys);
1251
+ const getUniqueFields = (where) => options.onConflictFields ?? (Utils.isPlainObject(where) ? Object.keys(where).flatMap(key => Utils.splitPrimaryKeys(key)) : meta.primaryKeys);
1252
+ const uniqueFields = getUniqueFields(allWhere[0]);
1253
+ // an empty condition identifies no row, it must not turn into a reload condition matching every row
1254
+ const getRowUniqueFields = (where) => Utils.isPlainObject(where) && !Utils.hasObjectKeys(where) ? uniqueFields : getUniqueFields(where);
1252
1255
  const platform = this.getPlatform();
1253
1256
  const returning = getOnConflictReturningFields(meta, data[dataIndexes[0]], uniqueFields, options, platform);
1254
1257
  if (options.onConflictWhere && res.rows?.length !== allData.length) {
@@ -1268,7 +1271,9 @@ export class EntityManager {
1268
1271
  dataIndexes.forEach((index, idx) => {
1269
1272
  const item = data[index];
1270
1273
  where.$or[idx] = {};
1271
- const props = Array.isArray(uniqueFields) ? uniqueFields : Object.keys(item);
1274
+ // the inputs of one batch can be identified by different unique keys
1275
+ const fields = getRowUniqueFields(allWhere[idx]);
1276
+ const props = Array.isArray(fields) ? fields : Object.keys(item);
1272
1277
  props.forEach(prop => {
1273
1278
  where.$or[idx][prop] = item[prop];
1274
1279
  });
@@ -1294,7 +1299,10 @@ export class EntityManager {
1294
1299
  });
1295
1300
  return tmp;
1296
1301
  });
1297
- const isMatch = (cond, idx) => this.#comparator.matching(entityName, cond, comparableRows[idx]);
1302
+ // rows carry the keys of every condition in the batch, compare only this one's (an empty one must not match)
1303
+ const isMatch = (cond, idx) => this.#comparator.matching(entityName, cond, Utils.hasObjectKeys(cond)
1304
+ ? Object.fromEntries(Object.entries(comparableRows[idx]).filter(([k]) => k in cond))
1305
+ : comparableRows[idx]);
1298
1306
  // When every condition key is a comparable prop checked with `!==`, a matching row has the same primitive
1299
1307
  // values, so rows can be grouped by those values once instead of comparing every row for every entity.
1300
1308
  // Props outside `comparableProps` are skipped by the comparator, so they never qualify for grouping.
@@ -1333,14 +1341,15 @@ export class EntityManager {
1333
1341
  if (loadPK.size !== data2.length && Array.isArray(uniqueFields)) {
1334
1342
  for (let i = 0; i < allData.length; i++) {
1335
1343
  const data = allData[i];
1336
- const cond = uniqueFields.reduce((a, b) => {
1344
+ const fields = getRowUniqueFields(allWhere[i]);
1345
+ const cond = fields.reduce((a, b) => {
1337
1346
  // @ts-ignore
1338
1347
  a[b] = data[b];
1339
1348
  return a;
1340
1349
  }, {});
1341
1350
  const entity = entitiesByData.get(data);
1342
1351
  const row = data2.find(item => {
1343
- const pk = uniqueFields.reduce((a, b) => {
1352
+ const pk = fields.reduce((a, b) => {
1344
1353
  // @ts-ignore
1345
1354
  a[b] = item[b];
1346
1355
  return a;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/core",
3
- "version": "7.2.4-dev.12",
3
+ "version": "7.2.4-dev.14",
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.4-dev.12';
156
+ static #ORM_VERSION = '7.2.4-dev.14';
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}`;