@mikro-orm/core 6.4.2-dev.4 → 6.4.2-dev.6

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.
@@ -501,11 +501,10 @@ class MetadataDiscovery {
501
501
  }
502
502
  findReferencingProperties(meta, metadata) {
503
503
  for (const meta2 of metadata) {
504
- const prop2 = meta2.relations.find(prop2 => {
505
- return prop2.kind !== enums_1.ReferenceKind.SCALAR && prop2.type === meta.className;
506
- });
507
- if (prop2) {
508
- meta.referencingProperties.push({ meta: meta2, prop: prop2 });
504
+ for (const prop2 of meta2.relations) {
505
+ if (prop2.kind !== enums_1.ReferenceKind.SCALAR && prop2.type === meta.className) {
506
+ meta.referencingProperties.push({ meta: meta2, prop: prop2 });
507
+ }
509
508
  }
510
509
  }
511
510
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/core",
3
- "version": "6.4.2-dev.4",
3
+ "version": "6.4.2-dev.6",
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.2.0",
66
66
  "globby": "11.1.0",
67
- "mikro-orm": "6.4.2-dev.4",
67
+ "mikro-orm": "6.4.2-dev.6",
68
68
  "reflect-metadata": "0.2.2"
69
69
  }
70
70
  }
@@ -348,6 +348,7 @@ class UnitOfWork {
348
348
  unsetIdentity(entity) {
349
349
  this.identityMap.delete(entity);
350
350
  const wrapped = (0, entity_1.helper)(entity);
351
+ const serializedPK = wrapped.getSerializedPrimaryKey();
351
352
  // remove references of this entity in all managed entities, otherwise flushing could reinsert the entity
352
353
  for (const { meta, prop } of wrapped.__meta.referencingProperties) {
353
354
  for (const referrer of this.identityMap.getStore(meta).values()) {
@@ -355,8 +356,13 @@ class UnitOfWork {
355
356
  if (Utils_1.Utils.isCollection(rel)) {
356
357
  rel.removeWithoutPropagation(entity);
357
358
  }
358
- else if (rel === entity) {
359
- delete (0, entity_1.helper)(referrer).__data[prop.name];
359
+ else if (rel && (prop.mapToPk ? (0, entity_1.helper)(this.em.getReference(prop.type, rel)).getSerializedPrimaryKey() === serializedPK : rel === entity)) {
360
+ if (prop.formula) {
361
+ delete referrer[prop.name];
362
+ }
363
+ else {
364
+ delete (0, entity_1.helper)(referrer).__data[prop.name];
365
+ }
360
366
  }
361
367
  }
362
368
  }